• Turner Gau
  • NEWBIE
  • 10 Points
  • Member since 2016

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

Discovered this bug today with the new year

Just open the Execute Anonymous Window and run the following:

System.Debug(DateTime.newInstance(Date.newInstance(2018,12,30), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));
System.Debug(DateTime.newInstance(Date.newInstance(2018,12,31), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));

See the results in the log as: 2019-12-30 and 2019-12-31 (Why are these coming as 2019, even with whatever timezone you/your org are in, a full year difference makes no sense at all)

Do the same for these dates for last year and they come out correctly:
System.Debug(DateTime.newInstance(Date.newInstance(2017,12,30), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));
System.Debug(DateTime.newInstance(Date.newInstance(2017,12,31), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));

Can anyone explain this?  

Discovered this bug today with the new year

Just open the Execute Anonymous Window and run the following:

System.Debug(DateTime.newInstance(Date.newInstance(2018,12,30), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));
System.Debug(DateTime.newInstance(Date.newInstance(2018,12,31), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));

See the results in the log as: 2019-12-30 and 2019-12-31 (Why are these coming as 2019, even with whatever timezone you/your org are in, a full year difference makes no sense at all)

Do the same for these dates for last year and they come out correctly:
System.Debug(DateTime.newInstance(Date.newInstance(2017,12,30), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));
System.Debug(DateTime.newInstance(Date.newInstance(2017,12,31), Time.newInstance(0,0,0,0)).format('YYYY-MM-dd'));

Can anyone explain this?