Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
amitdadri
Contributor
Contributor

Error in converting string to Date

Hi All

 

I have used below code to convert from string to date , but still I'm getting the below errors

 

0683p000009M1vG.png                                                               

I have used below expression

routines.utils.stringToDate(row2.StartDate,  "dd-MM-yyyy")

 

and I'm getting below error

java.text.ParseException: Unparseable date: "1/1/2019"
    at java.text.DateFormat.parse(Unknown Source)
    at routines.utils.stringToDate(utils.java:707)
    at sf_atos.testing_0_1.testing.tFixedFlowInput_2Process(testing.java:896)
    at sf_atos.testing_0_1.testing.runJobInTOS(testing.java:2104)
    at sf_atos.testing_0_1.testing.main(testing.java:1948)
java.text.ParseException: Unparseable date: "25/01/2019"
    at java.text.DateFormat.parse(Unknown Source)
    at routines.utils.stringToDate(utils.java:707)
    at sf_atos.testing_0_1.testing.tFixedFlowInput_2Process(testing.java:896)
    at sf_atos.testing_0_1.testing.runJobInTOS(testing.java:2104)
    at sf_atos.testing_0_1.testing.main(testing.java:1948)
.---------.
|tLogRow_2|
|=-------=|
|StartDate|
|=-------=|
|null     |
|null     |
'---------'

 

The output is coming null

Labels (3)
1 Solution

Accepted Solutions
ThWabi
Creator II
Creator II

Hello amitdadri,

 

if your inputs 1/1/2019, 25/01/2019, 23/1/2019 are of type Date, then you can convert them to "yyyy-MM-dd" Strings with TalendDate.formatDate("yyyy-MM-dd", row1.yourInputDate). If your inputs are Strings, convert them to Date format with TalendDate.parseDate("dd/MM/yyyy", row5.yourInputString) first, then apply the formatDate function mentioned before.

 

Best regards,

 

Thomas

 

View solution in original post

7 Replies
amitdadri
Contributor
Contributor
Author

Manoj_MUTHURAJA
Creator
Creator

Is it possible to put the screen capture of your tmap? it will be useful to see the datatype you used in the source and target

 

try the following functions:

TalendDate.format("yyyy-MM-dd", row.myDate)

 

TalendDate.parseDate("dd.MM.yyyy",row1.Clearing_Date) 

 

TalendDate.formatDate("yyyyMMdd",row6.Date)

 

(Var.date==null || Var.date.isEmpty())? null : TalendDate.parseDate("MM/dd/yyyy",TalendDate.formatDate("MM/dd/yyyy",TalendDate.parseDate("MM/dd/yyyy",Var.date)))

 

amitdadri
Contributor
Contributor
Author

Thanks for the reply @Manoj_MUTHURAJA

 

0683p000009M1vV.png          

what you have suggested is giving bit different output for two different values i provided

 

Input values 1/1/2019    and  25/01/2019

corresponding output that i got

|StartDate |
|=--------=|
|2019-01-01|
|2021-01-01|
'----------'

 

For first value it's working fine , but for second value its giving wrong output.

Would be a great help if you suggest solution to this

Manoj_MUTHURAJA
Creator
Creator

it's normal the data is of different type because the the function you gave is yyyy-mm-dd 

 

now you can change the format to dd-mm-yyyyy ,try and see and tell me what it gives

amitdadri
Contributor
Contributor
Author

i have changed the format as you told, still I'm getting the wrong value, the input data will be same as of the values I'm giving as input eg 1/1/2019 , 25/01/2019 , 23/1/2019 ,

and I need the output in "yyyy-MM-dd" format
Manoj_MUTHURAJA
Creator
Creator

I don't know how to help more.Either You can put the screen capture of the full tmap or otherwise use the tmap:

use this link for reference 

 

https://www.youtube.com/watch?v=2TCmUs8_9uM

 

please look at the screen capture I have attached below.

I am sure it could be useful for you.


Capture12.PNG
ThWabi
Creator II
Creator II

Hello amitdadri,

 

if your inputs 1/1/2019, 25/01/2019, 23/1/2019 are of type Date, then you can convert them to "yyyy-MM-dd" Strings with TalendDate.formatDate("yyyy-MM-dd", row1.yourInputDate). If your inputs are Strings, convert them to Date format with TalendDate.parseDate("dd/MM/yyyy", row5.yourInputString) first, then apply the formatDate function mentioned before.

 

Best regards,

 

Thomas