• Parra d'Andert
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I have an issue with Date formating for the following dates 28-Dec-2014, 29-Dec-2014, 30-Dec-2014, 31-Dec-2014.  Whenever I format one of these dates using either apex of Visualforce, a year is added to the formated date (31 Dec 2014 becomes 31 Dec 2015)
Other dates work fine.

This is really easy to reproduce using execute anonymous:

Date testDate = Date.newInstance(2014, 12, 31);
System.debug('Date.newInstance(2014, 12, 31) : ' + testDate);
Output: Date.newInstance(2014, 12, 29) : 2014-12-30 00:00:00

System.debug('year : ' + testDate.year() + ' - month : ' + testDate.month() + ' - day : ' + testDate.day());
Output: year : 2014 - month : 12 - day : 30

System.debug('Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()) : ' + Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()));
Output: Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()) : 2014-12-29 23:00:00

System.debug('Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()).format("dd MMM YYYY") : ' + Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()).format('dd MMM YYYY'));
Output: Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()).format("dd MMM YYYY") : 30 Dec 2015

The visualforce formating rendering the same is:
<apex:outputText value="{0, date, dd MMM YYYY}"><apex:param value="{!testDate}"/></apex:outputText>

Can someone please explain me what's going on?

Thanks
Hi,

I have an issue with Date formating for the following dates 28-Dec-2014, 29-Dec-2014, 30-Dec-2014, 31-Dec-2014.  Whenever I format one of these dates using either apex of Visualforce, a year is added to the formated date (31 Dec 2014 becomes 31 Dec 2015)
Other dates work fine.

This is really easy to reproduce using execute anonymous:

Date testDate = Date.newInstance(2014, 12, 31);
System.debug('Date.newInstance(2014, 12, 31) : ' + testDate);
Output: Date.newInstance(2014, 12, 29) : 2014-12-30 00:00:00

System.debug('year : ' + testDate.year() + ' - month : ' + testDate.month() + ' - day : ' + testDate.day());
Output: year : 2014 - month : 12 - day : 30

System.debug('Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()) : ' + Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()));
Output: Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()) : 2014-12-29 23:00:00

System.debug('Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()).format("dd MMM YYYY") : ' + Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()).format('dd MMM YYYY'));
Output: Datetime.newInstance(testDate.year(), testDate.month(), testDate.day()).format("dd MMM YYYY") : 30 Dec 2015

The visualforce formating rendering the same is:
<apex:outputText value="{0, date, dd MMM YYYY}"><apex:param value="{!testDate}"/></apex:outputText>

Can someone please explain me what's going on?

Thanks