How to compare current date & time with sys_updated_on?

Ankita9
Tera Contributor

Hi All,

 

How can I compare current date & time with sys_updated_on? My requirement is to check whether the record was update recently or not. 

 

TIA

1 REPLY 1

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Ankita9 

 

You can code using below code:

 

var updateDT = new GlideDateTime('sys_updated_on');
var currentDT= new GlideDateTime();

var diff = GlideDateTime.subtract(date1, date2);
gs.info(diff.getDisplayValue());

 

In this code, diff will store the duration between the dates so based on your requirement you can check if it was less than 1 day or 2 days or 1 week etc according to your definition of updated recently.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023