Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

View solution in original post

2 Replies
Anonymous
Not applicable
Author

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

Anonymous
Not applicable
Author

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