Date difference in scoped application

aparnateja
Kilo Explorer

Hi All,

I want the difference of two date fields (to_date - from_date) in scoped application. I tried using dateDiff() method, but it was showing error that dateDiff is not allowed in scoped applications.

Could any one of you please help me in this regard.

Thanks in advance.

Thanks,

Aparna

7 REPLIES 7

Simon46
ServiceNow Employee
ServiceNow Employee

Hello Aparna,



The function Subtract() expects two parameters of class "GlideDateTime", in your example you were parsing in "GlideElementGlideObject" (ie. current.to_date), hence why you are seeing the error.



You need to parse the glide value into and create a GlideDateTime object. Please note my line 1 and 2 is different to your code.



Kind regards,


Simon Liang


Hi Simon,



I wrote the code like this:


var t = new GlideDateTime(current.to_date);


var f = new GlideDateTime(current.from_date);


var dur = GlideDateTime.subtract(t, f);


gs.addInfoMessage(dur);



I am getting some different date as info Message.


error.PNG


Thanks,


Aparna


Use gs.addInfoMessage(dur.getDisplayValue());