Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

calculate difference between two dates in scoped application

ggg
Giga Guru

In my NON scoped app i used gs.dateDiff to get difference between two dates and it worked perfectly.

I am now in a scoped app and cannot use gs.dateDiff.

says to use GlideDateTime.subtract(d1, d2);

that returns a duration object of the form: 2 Days 23 Hours

How do i convert the duration object to seconds?

 

1 ACCEPTED SOLUTION

Try this:

var t = new GlideDateTime();
var f = new GlideDateTime('2019-04-08 16:43:33');
var dur = GlideDateTime.subtract(t, f);

var duration = dur.getNumericValue();
var durationSeconds = (duration/1000);

gs.info(t);
gs.info(dur.getDisplayValue());
gs.info(durationSeconds );


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

4 REPLIES 4

Harshinya1
Mega Guru

This post might give you an idea

 

https://community.servicenow.com/community?id=community_question&sys_id=3e52d761db101fc01dcaf3231f96199c

 

Please mark helpful/correct if the content solved your issue

 

Thanks,

Harshinya

Prateek kumar
Mega Sage

Take a look at this

https://community.servicenow.com/community?id=community_question&sys_id=11010fa5db98dbc01dcaf3231f96194f


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

i have looked at posts and documentation and it is still not clear ...

I need the actual script ...

Try this:

var t = new GlideDateTime();
var f = new GlideDateTime('2019-04-08 16:43:33');
var dur = GlideDateTime.subtract(t, f);

var duration = dur.getNumericValue();
var durationSeconds = (duration/1000);

gs.info(t);
gs.info(dur.getDisplayValue());
gs.info(durationSeconds );


Please mark my response as correct and helpful if it helped solved your question.
-Thanks