TalendDate.formatDate - Incorrect Year result

Five Stars

TalendDate.formatDate - Incorrect Year result

Hi! I use TalendDate.formatDate to pull the Year out of a Date however for all December dates in 2015 (i.e 2015-12-29) it is assigning a 2016 year? how is this happening, how can I fix it?


Accepted Solutions
Sixteen Stars

Re: TalendDate.formatDate - Incorrect Year result

Actually forget that, the problem is your "YYYY". It should be "yyyy". Try that. This should explain it .....

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html


All Replies
Sixteen Stars

Re: TalendDate.formatDate - Incorrect Year result

Can you show us your code?

Five Stars

Re: TalendDate.formatDate - Incorrect Year result

TalendDate.formatDate("YYYY",row1.ship_date)

Sixteen Stars

Re: TalendDate.formatDate - Incorrect Year result

This *could* be a timezone calculation issue. Try using formatDateInUTC and see if that solves your issue. 

Sixteen Stars

Re: TalendDate.formatDate - Incorrect Year result

Actually forget that, the problem is your "YYYY". It should be "yyyy". Try that. This should explain it .....

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Ten Stars

Re: TalendDate.formatDate - Incorrect Year result

For those not accustomed to reading Java documentation, "Y" in Java's SimpleDateFormat indicates "Week year" which extends the start of a year to include the entire week. Borrowing the example of 2015-12-29 (a Tuesday), this date evaluates to 2016 because 2016-01-01 (a Friday) is in the same week.

The results can vary depending on the calendar in use and the start day of the week (Monday vs. Sunday).

In short, use 'y' for years unless you have a very specific need.