Is the record creation time "GMT"?

bonsai
Mega Sage

※This is the Paris version.

 

I thought about deleting all the scripts created after 1 hour with the following script.

var time_difference =1000;
var nTime = new GlideDateTime();
nTime.addSeconds(-3600+time_difference); //1 hour ago

var grid_del = new GlideRecord(table_name);
grid_del.addQuery("sys_created_on", ">", nTime);
grid_del.query();
gs.info(grid_del.getRowCount());
grid_del.deleteMultiple(); 

 

However, the result of "grid_del.addQuery (" sys_created_on ","> ", nTime);" was not what I expected.

The timezone of the instance I'm currently using is other than "GMT".

 

When using ".addQuery (" sys_created_on ","> ", nTime);" in a script, is the time of "sys_created_on" a GMT value?
When I changed the time zone to GMT and executed it with "time_difference = 0", it was the expected behavior.
I'm in trouble because I can't understand how it works.

1 ACCEPTED SOLUTION

Hi,

internally in XML the sys_created_on value is stored in GMT.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you want to check records created 1 hr ago from now?

var nTime = new GlideDateTime(); -> this is always in GMT

then do this

Before deleting print the count

var nTime = new GlideDateTime();
nTime.addSeconds(-3600); //1 hour ago

var grid_del = new GlideRecord(table_name);
grid_del.addQuery("sys_created_on", "<", nTime);
grid_del.query();
gs.info(grid_del.getRowCount());
//grid_del.deleteMultiple(); 

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Will the value set for "sys_created_on" be the GMT value even if the timezone is changed to something other than GMT?

I thought I needed to add the diff seconds in ".addSeconds".

Hi,

internally in XML the sys_created_on value is stored in GMT.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you for answering!
I am convinced.