Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

String to date Conversion

I'm new to Talend. Can anyone help me in converting String(20150901) to Date(2015-09-01).
Thanks in Advance
Labels (2)
7 Replies
Anonymous
Not applicable
Author

Hello kalkavi,
If you want to change the String to Date, you can use TalendDate.parseDate("yyyyMMdd", yourdate). 

Lin LIN
Consultant BI/Talend
Synaltic Group
Anonymous
Not applicable
Author

Thanks louislinlin
Please find the following error. I have also pasted the screen shot. Thanks for your help.
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]Exception in component tMap_1[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]java.lang.RuntimeException: java.text.ParseException: Unparseable date: ""[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at routines.TalendDate.parseDate(TalendDate.java:895)[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at routines.TalendDate.parseDate(TalendDate.java:839)[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at local_project.testjob_0_1.TestJob.tFileInputFullRow_1Process(TestJob.java:1231)[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at local_project.testjob_0_1.TestJob.runJobInTOS(TestJob.java:1618)[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at local_project.testjob_0_1.TestJob.main(TestJob.java:1475)[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]Caused by: java.text.ParseException: Unparseable date: ""[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at java.text.DateFormat.parse(Unknown Source)[/font][/color]

[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif] at routines.TalendDate.parseDate(TalendDate.java:881)[/font][/color]
Anonymous
Not applicable
Author

kalkavi,
You should change to yourdate == null || "".equals(yourdate.trim()) ? null : TalendDate.parseDate("yyyyMMdd", yourdate)

Lin LIN
Consultant BI/Talend
Synaltic Group
Anonymous
Not applicable
Author

Thanks louislinlin for your help. It works fine.
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]Also, on another topic. Is there a function to convert String to Long. do i have to post as a seperate topic.?[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]Any help would be appreciated.[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]Thanks[/font][/color]
Anonymous
Not applicable
Author

kalkavi,
There is the founction Long.parseLong(yourString) in Java. So you can do the same thing : yourString == null || "".equals(yourString.trim()) ? null : Long.parseLong(yourString)

Lin LIN
Consultant BI/Talend
Synaltic Group
Anonymous
Not applicable
Author

hi,
I personally use :
Long myLong = Long.valueOf(<your string here>);

If your string is not a number he will throws a NumberFormatException.

CSen
Anonymous
Not applicable
Author

Thanks louislinlin & csen