Last active
August 26, 2017 19:21
-
-
Save johndstein/4a49e115b5ca85eaad4a4d13cd5a132e to your computer and use it in GitHub Desktop.
Salesforce Date and Datetime anomaly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you create a Datetime instance from a date and then create a Date | |
// instance from the year, month and day of the datetime, you probably | |
// won't get the date instance you expect. | |
Datetime dt = Datetime.newInstance(2017,12,31); | |
System.debug('dt: ' + Date.newInstance(dt.year(),dt.month(),dt.day())); | |
Datetime fromdt = Date.valueOf('2017-12-31'); | |
System.debug('date: ' + Date.valueOf('2017-12-31')); | |
System.debug('fromdt: ' + fromdt); | |
System.debug('fromdt Date: ' + Date.newInstance(fromdt.year(),fromdt.month(),fromdt.day())); | |
// 15:18:52.1 (2422833)|USER_DEBUG|[2]|DEBUG|dt: 2017-12-31 00:00:00 | |
// 15:18:52.1 (2502589)|USER_DEBUG|[4]|DEBUG|date: 2017-12-31 00:00:00 | |
// 15:18:52.1 (2547071)|USER_DEBUG|[5]|DEBUG|fromdt: 2017-12-31 00:00:00 | |
// 15:18:52.1 (2652146)|USER_DEBUG|[6]|DEBUG|fromdt Date: 2017-12-30 00:00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment