Issue with glideDateTime in scoped application

brittany_sorrel
Kilo Expert

I'm currently using the subtract function for two GlideDateTime values (since scoped apps will not allow you to use datediff). The problem is that I can set the date to a week ago or a month ago and the value it returns everytime is two hour difference when asking for the display of the result. Has anyone else experienced this issue in a scoped application?

Here is an example of values and what is returned.

Today's date:2018-05-22 18:30:58
Exp Date:2018-05-15 20:59:55
Diff (using subtract):1969-12-25 02:28:56
diff display (using getDisplayValueInternal):20:28:56

 

I've tried to take the value returned from the subtract and use javascript to get the difference between that and the beginning of time, but .getTime() is not accepted. Any assistance is greatly appreciated.

 

Thanks,

Britt

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

it works ok for me. here is a sample script that i tested in scope:

var sdt = new GlideDateTime();
sdt.setValue('2018-01-01 12:30:00');
var edt = new GlideDateTime();
edt.setValue('2018-01-01 20:00:00');
var diff = GlideDateTime.subtract(sdt, edt);
// get the number of ms between the 2 dates
var dur = diff.getNumericValue();
gs.info(dur);
// get the number of hours
var hrs = dur / 1000 / 60 / 60;
gs.info(hrs);
// output the diff display value
gs.info(diff.getDisplayValue());

View solution in original post

2 REPLIES 2

Jon Barnes
Kilo Sage

it works ok for me. here is a sample script that i tested in scope:

var sdt = new GlideDateTime();
sdt.setValue('2018-01-01 12:30:00');
var edt = new GlideDateTime();
edt.setValue('2018-01-01 20:00:00');
var diff = GlideDateTime.subtract(sdt, edt);
// get the number of ms between the 2 dates
var dur = diff.getNumericValue();
gs.info(dur);
// get the number of hours
var hrs = dur / 1000 / 60 / 60;
gs.info(hrs);
// output the diff display value
gs.info(diff.getDisplayValue());

Thanks for the help! 🙂

The getNumericValue did the trick. The other method I was using was giving me weird results.