Query on getDayOfMonth() method

tj2
Kilo Contributor

Hi,

When we run the following code in one of our server side scripts we get the output as 1

var gdt = new GlideDateTime("2012-8-02 06:00:00");
gs.log(gdt.getDayOfMonth());

Whereas when we run the following code in one of our server side scripts we get the output as 2
var gdt = new GlideDateTime("2012-8-02 07:00:00");
gs.log(gdt.getDayOfMonth());

Could you advice why this difference in the Day of month?

Thanks

7 REPLIES 7

w_bouwer
Mega Expert

Can you check whether the server has a timezone offset? Depending on where you run your script, the session data is either included or not. If it is run as system, it takes the timezone of the server. This could be why your day of the month is stating 1 instead of 2.

Try:



var gdt = new GlideDateTime('2012-8-02 06:00:00');
gs.print(gdt.getTZOffset()/3600000);
gs.print(gdt.getLocalDate());


It will display the offset in seconds, so this will show the offset in hours. Demo instances by default are -7(!). The second print shows the date on which the getDayOfMonth is based. I've been able to reproduce this on the demo environment.

Regards,

Wesley


jason_petty
Tera Expert

I am also able to reproduce this on my demo environment that I have up now. I guess it depends on the time of day you run this since the timezone offset is used.


i am in GMT format and system is in GMT and My Offset is 0

if i give date above 8 then it showing correct value ..for less than then it showing only day less


sample code

var gdt = new GlideDateTime("2012-06-17 05:00:00");
gs.print(gdt);
gs.print(gdt.getDayOfMonth());

Returns:

***Script: 2012-06-17 05:00:00
***Script: 16