TalendDate.formatDate - Incorrect Year result

Highlighted
Six 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
Community Manager

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
Community Manager

Re: TalendDate.formatDate - Incorrect Year result

Can you show us your code?

Six Stars

Re: TalendDate.formatDate - Incorrect Year result

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

Community Manager

Re: TalendDate.formatDate - Incorrect Year result

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

Community Manager

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.

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

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 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now