gs.endOfLastMonth() and gs.beginningOfLastMonth() returns GMT

Stewe Lundin
Mega Guru

Hi!
gs.endOfLastMonth() and gs.beginningOfLastMonth() returns GMT

is this something I have to take under consideration when I ask questions to the database via the glide record


Or do I need to convert the time to GMT from my private function that returns the first or last date/time in a given month/year.

I I ask my function
ax-first_last_date("now",2017) it now returns

2017-11-01 00:00:012017-11-30 23:59:59

If i ask the same with gs.endOfLastMonth() and gs.beginningOfLastMonth()

It returns

2017-09-30 22:00:00 and 2017-10-30 22:59:59

this is to replace @javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth() when the GliceSystem options is not enough.

I'm located in a CET zone with daylights savings.

Did some changes to the question to make it clearer.

3 REPLIES 3

Fabian Kunzke
Kilo Sage
Kilo Sage

Hello,



According to this:



Instantiates a new GlideDateTime object with the current date and time in GMT format.



The returned timestamp will always be in GMT format (at least as far as i know). Alternatively you can set the format manually:



http://wiki.servicenow.com/index.php?title=GlideDateTime#setValueUTC.28dt.2C_format.29



Sets a date and time value using the UTC time zone and the specified date and time format. This method throws a runtime exception if the date and time format used in the dt parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught. This method is available starting with the Eureka release.



var gdt = new GlideDateTime("2011-01-01 12:00:00");


gdt.setValueUTC("15-02-2011 08:00:00", "dd-MM-yyyy HH:mm:ss");


gs.print(gdt.getValue());



For more detailled methods to set timezones and daylight saving options take a look here:



http://wiki.servicenow.com/index.php?title=GlideDateTime#gsc.tab=0



Greetings


Fabian


As far as I know and all the timestamps in my tables are CET daylight savings but is this how it is presented to me because of my settings but are stored in GMT?


Hello,



Per default they are stored like this in a GlideDateTime/GlideDate object. The behaiviour (e.g. the daylight saving and timezone) can be changed with functions like .isDTS() or .setTZ(). Therefore not all of your timestamp are stored in GMT but if you initialize a GlideDateTime object without setting its values correctly it will default to GMT without daylight saving. Therefore when grabbing a timestamp and putting it into such an object it will default to GMT.



Greetings


Fabian