One Star

string to date

Hi,
I have a string like that "16/01/2008 09:04:12 AM" and i need to have a date from this string.
i try with TalendDate.parseDate("dd/MM/yyyy HH:mm:ss aa", madate) but it doesn't work.
the log is Unparseable date: "16/01/2008 09:04:12 AM"
Have u got an idea to help me ?

20 REPLIES
One Star

Re: string to date

I tried your date string with your format and it works for me. Maybe you have problems with your Locale.
For a quick test just generate a date with your format and make a visual compare.
Bye
Volker
Community Manager

Re: string to date

Hi besco
Try this method:
TalendDate.parseDateLocale("dd/MM/yyyy HH:mm:ss aa",mydate,"EN")
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: string to date

it's ok now but another problem appears when i load my date in oracle. if i have 2 date like that
16/01/2008 09:04:12 AM
16/01/2008 09:04:12 PM
there's no difference in oracle.
About date, i've another question, how can i put a default value (date of day) for a oracle column.
i try in a tmap to put this
row1.ORIGINAL_FILE_DATE.equals("null") ? TalendDate.getDate("dd/MM/yyyy hh:mm:ss") : row1.ORIGINAL_FILE_DATE

and the syntax seems to be wrong.
thanks to help me!
One Star

Re: string to date

have you got any idea please ?
Community Manager

Re: string to date

Hello
row1.ORIGINAL_FILE_DATE.equals("null") ? TalendDate.getDate("dd/MM/yyyy hh:mm:ss") : row1.ORIGINAL_FILE_DATE

There is no wrong on the syntax, if there are some fileds are empty in Oracle table, you can try this code:
row1.ORIGINAL_FILE_DATE==null ? TalendDate.getDate("dd/MM/yyyy hh:mm:ss") : row1.ORIGINAL_FILE_DATE

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: string to date

this code is wrong
Exception in thread "Main Thread" java.lang.Error: Unresolved compilation problem: 
Type mismatch: cannot convert from Object&Serializable&Comparable to Date
Community Manager

Re: string to date

Hi
What's the schema type of row1.ORIGINAL_FILE_DATE in your case? I thought it was string, not Date.
If it is a Date type, we should parse a string to a Date.
row1.ORIGINAL_FILE_DATE==null ? TalendDate.parseDate("dd/MM/yyyy hh:mm:ss",TalendDate.getDate("dd/MM/yyyy hh:mm:ss") ): row1.ORIGINAL_FILE_DATE

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: string to date

Shong
I am getting the following error when I tried using the expression in tMap, row1.START_DATE_ACTIVE==null ? TalendDate.parseDate("dd/MM/yyyy hh:mm:ss",TalendDate.getDate("dd/MM/yyyy hh:mm:ss") ): row1.START_DATE_ACTIVE.
ErrorMessage:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Can you please let me know how I can avoid this error. Thanks in advance.
-Venkat
One Star

Re: string to date

Shong,
I figured out the issue. This thread helped me to fix my issue.
Thank you,
-Venkat
One Star

Re: string to date

hi,
how to convert string to date in tmap
my string is "06/04/2010" but its give a error
java .lang .numberformatexception
regards,
naveen
One Star

Re: string to date

Hi,
I have a string like that "2 November 2010" and i need to have a date from this string.
Any Idea how I can convert this using Talend ?
Thanks
Z

Re: string to date

One Star

Re: string to date

I tried the same with variable type as date and expression as
TalendDate.parseDate("dd/MM/yyyy HH:mm:ss",row1.Target_Resolution_Date)

where row1.Target_Resolution_Date is of type string
in tMap component but i faced the following error
Exception in component tMap_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "13 12 2011 06:00:00"
at routines.TalendDate.parseDate(TalendDate.java:643)
at honey.create_my_first_job_0_1.Create_My_First_Job.tFileInputExcel_3Process(Create_My_First_Job.java:1566)
at honey.create_my_first_job_0_1.Create_My_First_Job.runJobInTOS(Create_My_First_Job.java:2312)
at honey.create_my_first_job_0_1.Create_My_First_Job.main(Create_My_First_Job.java:2186)
Caused by: java.text.ParseException: Unparseable date: "13 12 2011 06:00:00"
at java.text.DateFormat.parse(DateFormat.java:354)
at routines.TalendDate.parseDate(TalendDate.java:641)
... 3 more
disconnected
Job Create_My_First_Job ended at 12:58 18/01/2012.
One Star

Re: string to date

hi i want to convert string 7/17/2012 2:57:16 PM to date but it gives error
Exception in component tMap_2
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "7/17/2012 2:57:16 PM"
at routines.TalendDate.parseDateLocale(TalendDate.java:676)
at xml_to_mysql.xml_master_data_conversion_0_1.Xml_Master_Data_Conversion.tFileInputXML_4Process(Xml_Master_Data_Conversion.java:6989)
at xml_to_mysql.xml_master_data_conversion_0_1.Xml_Master_Data_Conversion.runJobInTOS(Xml_Master_Data_Conversion.java:8194)
at xml_to_mysql.xml_master_data_conversion_0_1.Xml_Master_Data_Conversion.main(Xml_Master_Data_Conversion.java:8062)
Caused by: java.text.ParseException: Unparseable date: "7/17/2012 2:57:16 PM"
at java.text.DateFormat.parse(DateFormat.java:337)
at routines.TalendDate.parseDateLocale(TalendDate.java:674)
... 3 more
disconnected
Regards,
naveen
One Star

Re: string to date

Hi
I have this problem with the convertion of a data String type to Date.
I have this value 2012-04-26T18:27:55, and i want to convert it to a Date data type
I need this format dd/mm/yyyy
This is the error message that is returnig:
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "2012-04-26T18:27:55
One Star

Re: string to date

Hi
I have this problem with the convertion of a data String type to Date.
I have this value 2012-04-26T18:27:55, and i want to convert it to a Date data type
I need this format dd/mm/yyyy
This is the error message that is returnig:
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "2012-04-26T18:27:55

I have the same issue. Did you solved it or can anybody else can help me to make this working?
One Star

Re: string to date

try below code which help you to parse date string into date format, note you can modify your output date format as per your requirement.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
SimpleDateFormat output = new SimpleDateFormat("dd/MM/yyyy");
Date d = sdf.parse(time);
String formattedTime = output.format(d);
One Star

Re: string to date

Tanks for you reply umeshrakhe.
I solved it another way by setting the pattern in the tXMLMap and changing the input datatype in the Tree schema editor.
Cheers!
One Star

Re: string to date

My data is coming like this 2016-10-15 16:50:11, I want this in yyyymmdd format.How can I do this by using Tmap.
Can any one please suggest.
Appreciate for help.
Thanks its done now .
Ten Stars

Re: string to date

My data is coming like this 2016-10-15 16:50:11, I want this in yyyymmdd format.How can I do this by using Tmap.
Can any one please suggest.
Appreciate for help.
Thanks its done now .

it depend from how Your data coming - as string or as date? ad what output format - string or date
in any case it is combination of TalendDate.formatDate and TalendDate.parseDate
for example if it coming as date and output as string
TalendDate.formatDate("yyyyMMddHH",dateColunName)
if it coming as string and must be converted to string as well:
TalendDate.formatDate("yyyyMMddHH",TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","2016-10-15 16:50:11"))
In tMap when You open Build Expression windows You can read short information about each function (not all but many of them) - look for input and output values, like on pictures
   
-----------