Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

( Date field) Converting Seconds into days

aahitha2
Mega Expert

Hi All,

I Have  one date field named as date1 and i need to differentiate this date1 field with current date.

var diff= gs.diff(date1.getDisplayValue(),gs.now().getDisplayValue(),true) ---- Now i need to convert these seconds into days.

var days=parseInt((diff/(60*60*24)));

 

But not working as expected, it showing one day delay to expected day.

 

Can any one help.

 

Thanks,

Aahitha

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron

Hi,

It is a date field and not date/time field.

Can you tell for example what date are you comparing?

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

ggg
Giga Guru

an example of dateDiff that may help:

var date1 = new GlideDateTime();
var date2 = new GlideDateTime();
date1.setDisplayValueInternal('2014-01-01 12:00:00');
date2.setDisplayValueInternal('2014-01-03 12:00:00');


var diffDays = gs.dateDiff(date1.getDisplayValue(), date2.getDisplayValue(), true);
gs.info(diffDays/(60*60*24)