Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
elkhounds
Creator

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

 

Labels (2)
1 Solution

Accepted Solutions
PhilHibbs
Creator II

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

3 Replies
elkhounds
Creator
Author

Anonymous
Not applicable

Hi @elkhounds 

 

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

0683p000009M8GV.png

 

0683p000009M8h5.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

PhilHibbs
Creator II

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