TalendDate.formatDate - Incorrect Year result

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?


Accepted Solutions
Eight 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


All Replies
Eight 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

Highlighted
Employee

Re: TalendDate.formatDate - Incorrect Year result

The function TalendDate.addDate returns the wrong date when Dec 31st is entered. It should return 20171231, but it returns 20181231 instead. All other dates work fine except for Dec 31st. 

Here is my function: TalendDate.formatDate("YYYYMMdd",TalendDate.addDate(TalendDate.getCurrentDate(),-context.VP_days_back,"DD"))); 
System.out.println("status_File_Name_Date: "+globalMap.get("status_File_Name_Date")); 

When I run it on: Jan 2nd, 2018 

passing in 1 
status_File_Name_Date: 20180101 
2018-01-02 11:11:03|zBVARx|zBVARx|zBVARx|5904|EDA|addDate_test|_5xWZIO_eEeerDMq08aFbSQ|0.1|CERT||end|success|479 
[statistics] disconnected 

passing in 2 
status_File_Name_Date: 20181231 ****INCORRECT**** 
2018-01-02 11:07:59|w3opZP|w3opZP|w3opZP|12616|EDA|addDate_test|_5xWZIO_eEeerDMq08aFbSQ|0.1|CERT||end|success|674 
[statistics] disconnected 

passing in 3 
status_File_Name_Date: 20171230 
2018-01-02 11:09:08|WpgMSb|WpgMSb|WpgMSb|3760|EDA|addDate_test|_5xWZIO_eEeerDMq08aFbSQ|0.1|CERT||end|success|500 
[statistics] disconnected

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog