HOW TO PARSE LONG DATE FORMAT INTO DATE FORMAT YYYY-MM-DD HH:mm:ss

Six Stars

HOW TO PARSE LONG DATE FORMAT INTO DATE FORMAT YYYY-MM-DD HH:mm:ss

Hi all,

 Can anyone give me idea on how I will convert long date format into this kind of format "yyyy-MM-dd HH:mm:ss",

long date format is like this "Mon, 27 Feb 2017 08:14:13 GMT" then I want to have a resolution like this "2017-02-27 08:14:13". Is it possible by using t_map?

 

Thanks

Sixteen Stars

Re: HOW TO PARSE LONG DATE FORMAT INTO DATE FORMAT YYYY-MM-DD HH:mm:ss

Assuming your date is in a column called "date" and on a row called "row1", this will do it....

 

routines.TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", routines.TalendDate.parseDate("EEE, dd MMM yyyy HH:mm:ss z", row1.date))

You can use that in a tMap. This will only work if the date format is guaranteed and if it is not null. If the date format is not guaranteed you will need to validate the date format before running this code. If it could be null, you will need the following code....

row1.date!=null ? routines.TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", routines.TalendDate.parseDate("EEE, dd MMM yyyy HH:mm:ss z", row1.date)) : row1.date