Six Stars

TalendDate.formatDate - Incorrect Year result

Hello Talend experts.

 

I have a daily csv file that is arriving without the year. I have come up with the following expression in tmap to correct this:

 

TalendDate.parseDate("yyyy MMM dd hh:mm:ss", TalendDate.getDate("CCYY") + " " + row2.Timestamp) 

 

The issue I am looking for help on is what to do on January 1 when I run this script. With the above expression, the new year date will be concatenated to the date string instead of the previous years. Is there a way to fix this?

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: TalendDate.formatDate - Incorrect Year result

Hi.

 

You could just replace TalendDate.getDate("CCYY") with the following, which will return the year for yesterday's date:

 

TalendDate.formatDate("yyyy", TalendDate.addDate(TalendDate.getCurrentDate(), -1, "dd")) 

 

Regards,

 

 

Chris

1 REPLY
Six Stars

Re: TalendDate.formatDate - Incorrect Year result

Hi.

 

You could just replace TalendDate.getDate("CCYY") with the following, which will return the year for yesterday's date:

 

TalendDate.formatDate("yyyy", TalendDate.addDate(TalendDate.getCurrentDate(), -1, "dd")) 

 

Regards,

 

 

Chris