gs.now returning yesterday's date!?

georgechen
Kilo Guru

Hi folks,

Just wondering if you could assist with the gs.now this time.       the published date is a date type in KB_knowlege table (knowledge base), a client has raised the published date set to yesterday's date when she created a new KB.     I was able to reproduce this in the early morning, and found a before business rule is setting the published date.   Please see screenshot below

find_real_file.png

gs.now() in script background seems to output today's date and it does not output the time,

find_real_file.png

find_real_file.png

the question come to my head, is the gs.now() reflecting client's local time?

Any feedback is appreciated.

Kind regards,

1 ACCEPTED SOLUTION

Did you try it like this?


var gdt = new GlideDateTime();


gs.print(gdt.getDate());



That is displaying properly for me.


View solution in original post

5 REPLIES 5

Robert Beeman
Kilo Sage

gs.now() returns GMT. You can use gs.nowDateTime() to see it in the user defined format and time zone.


GlideSystem Date and Time Functions - ServiceNow Wiki


Thanks Robert for your response.   gs.nowDateTime() returns date and time, but the the published is a date that will not accept the time.  



I tried to use gs.getDate() but it did not seem to return the date.       Any advise?



Regards,


Did you try it like this?


var gdt = new GlideDateTime();


gs.print(gdt.getDate());



That is displaying properly for me.


Inactive_Us1883
Mega Expert

Hi George,



If you want the current date with time you can used the gs.nowDateTime() method.


gs.now() will return the current date using GMT, so its not with client local time.


But if you want the time in you local time you can try with method setDisplayValueInternal GlideDateTime - ServiceNow Wiki



Hope these details will help you, and if you go through the you can find more details on these.



BR,


/Suraj