Client script to get 24 hours ago

e_wilber
Tera Guru

Hi everyone,


I need to get "24 hours" ago in my client script. I'm actually trying to do a query to get all records from this person created within the past 24 hours. How do query for created_on to get everything created within a day ago?

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I would do this using glideajax and then use one of the available server side date/time methods to do your query. Most of the time you're doing any querying or date/time work you want to do that on the server and then return the answer to the client script.



GlideAjax - ServiceNow Wiki


GlideDateTime - ServiceNow Wiki


GlideSystem Date and Time Functions - ServiceNow Wiki


Anurag Tripathi
Mega Patron
Mega Patron

Hi Eric,



I dont think you can do that in client side,   But seeing your requirement i fee you anyways have to get to the server side to dig for the users


So here is a server side code that will help you to get this done.


GlideSystem Date and Time Functions - ServiceNow Wiki


-Anurag

Harish Murikina
Tera Guru

Hi Eric,



      i used this script to add seconds.


May be it is helpful some what and modify the script as per you.



var sla_date= 0.1669*24*60*60;


var now_time = gs.nowDateTime();


var gdt = new GlideDateTime(now_time);


gdt.addSeconds(sla_date);


gs.print("old_date :"+now_time);  


gs.print("increaes_time:"+gdt.getValue());  




Regards,


Harish.