SSJS @Adjust on Javascript Dates - Be Backwarned!
Friday, March 5, 2010 at 1:46PM The following code will generate results that you may not expect:
var myDate = new Date(2010,2,15); //this is MARCH 15th, months for JSDate is zero based
myDate = @Adjust(myDate,0,-1,0,0,0,0);
You might expect myDate to now be 2/15/2010 ... its what the classic @Adjust @Formula would output. But there is a little more than meets the eye going on here.
new Date(2010,2,15) creates a new Date in the local time zone... In SSJS @Adjust() by default treats the date as a UTC timezone, so the results you will actually get is:
2/14/2010
Why you ask? Because we didnt specify a time in the date object, it's set to 12 Midnight, and going from March back to February crosses the line for Daylight savings, and the adjusted time changes from 12:00:00 midnight to 11:00:00 PM the previous day as you cross back.
The key is to specify the "[InLocalTime]" keyword to the @Adjust function, so the correct call would be:
@Adjust(myDate,0,-1,0,0,0,0,"[InLocalTime]")
Thanks to Dave Connelly and the IBM Team for chasing this one down!
Date,
ssjs in
Tips and Tricks 
Reader Comments (1)
Ah, daylight savings, what fun it causes us all!