Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
RVeitch_84
Creator
Creator

How to convert a string to a date.

I have strings in the following formats that I would like to convert into a date.

2021-05-21T11:45:15Z

2021-05-25T18:59:27.513Z

I've tried tMap with the following with no luck.

TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",row7.created_at); 

Error:

Exception in component tXMLMap_1 (w_xpath_bu_testdev_wDB_dateformat)

java.lang.RuntimeException: java.text.ParseException: Unparseable date: "2021-05-25T20:23:27Z"

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi

If you are trying to convert UTC time to local time, please take a look at this topic and try the solution.

 

Let me know if it works.

 

Regards

Shong

 

View solution in original post

4 Replies
Anonymous
Not applicable

It seems the data has different date format, you can check the length of string first, and then use corresponding date pattern to parse the string and convert it to Date. eg:

row7.created_at.length()>20?TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",row7.created_at):TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss'Z'",row7.created_at); 

RVeitch_84
Creator
Creator
Author

Another question, how can I convert that parsed date into local time from:

 

row7.created_at.length()>20?TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",row7.created_at):TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss'Z'",row7.created_at); 

 

2020-09-27T22:34:03Z this is what I'm getting

2020-09-27 17:34:03 But I need it in this format?

 

 

I was thinking of doing something like this:

0695b00000F8ywBAAR.jpg0695b00000F8ywzAAB.jpg0695b00000F8yxEAAR.jpg 

Thanks again.

 

 

Anonymous
Not applicable

Hi

If you are trying to convert UTC time to local time, please take a look at this topic and try the solution.

 

Let me know if it works.

 

Regards

Shong

 

RVeitch_84
Creator
Creator
Author

Thanks I ended up doing that same thing, see my example:

I had to add the option to look for a Null first.

 

Relational.NOT(Relational.ISNULL(row4.created_at1))?row4.created_at1.length()>20?TalendDate.parseDateInUTC("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",row4.created_at1):TalendDate.parseDateInUTC("yyyy-MM-dd'T'HH:mm:ss'Z'",row4.created_at1):TalendDate.parseDateInUTC("yyyy-MM-dd","0000-00-00");