Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

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 );

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
Giga Sage

Take a look at this

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

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 );