How to retrieve Month part of a Date returns previous Month instead. Bug?

Seven Stars

How to retrieve Month part of a Date returns previous Month instead. Bug?

The TalendDate.getPartOfDate("MONTH", " ") method returns the previous month instead of the current month. Is this a known bug? I need to identify the current and previous months of a date, but this method does not work as expected.

 

In this example, the returned month should October (10), but  TalendDate.getPartOfDate("MONTH"," ") returns September (9).  See attached file

 


Accepted Solutions
Highlighted
Eight Stars

Re: How to retrieve Month part of a Date returns previous Month instead. Bug?

I have encountered date libraries before that return the month using a zero-based index, so 0 is January and 11 is December. This may not be a bug. Existing code that relies on this behaviour would be broken if this were changed.

The java.util.Calendar class specifically has this behaviour:

https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html

 

MONTH

public static final int MONTH
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

See Also: JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER, UNDECIMBER, Constant Field Values

 

 

View solution in original post


All Replies
Highlighted
Seven Stars

Re: How to retrieve Month part of a Date returns previous Month instead. Bug?

Highlighted
Employee

Re: How to retrieve Month part of a Date returns previous Month instead. Bug?

Hi @elkhounds 

 

     Good catch and I also got the same result when I tried to run it in Talend 7.2

image.png

 

image.png

 

I have reported the Bug to the Product Team through JIRA. Please use the link below to track the progress of this ticket.

 

https://jira.talendforge.org/browse/TDI-43350

 

Appreciate again for identifying the issue :-)

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

Highlighted
Eight Stars

Re: How to retrieve Month part of a Date returns previous Month instead. Bug?

I have encountered date libraries before that return the month using a zero-based index, so 0 is January and 11 is December. This may not be a bug. Existing code that relies on this behaviour would be broken if this were changed.

The java.util.Calendar class specifically has this behaviour:

https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html

 

MONTH

public static final int MONTH
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

See Also: JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER, UNDECIMBER, Constant Field Values

 

 

View solution in original post

2019 GARTNER 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

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

Best Practices for Using Context Variables with Talend – Part 3

Read about some useful Context Variable ideas

Blog