Date difference in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 10:49 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 11:04 PM
Hello Aparna,
Maybe the use of the class "GlideDateTime" and the function "subtract" is what you're after.
Alternatively the use of "GlideDuration" may also be of use, as discussed by Cory.
https://community.servicenow.com/thread/193835#817614
Kind regards,
Simon Liang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 11:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 11:31 PM
Hello Aparna,
Can you try the following for me and let me know if it works.
var t = new GlideDateTime(current.to_date);
var f = new GlideDateTime(current.from_date);
var dur = GlideDateTime.subtract(t, f);
gs.info(dur.getDisplayValue());
Kind regards,
Simon Liang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 12:02 AM
Hi Simon,
It was not displaying any value and when I modified the last line as
gs.addInfoMessage(dur);
It was showing error.
Thanks,
Aparna