- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 08:25 AM
Hi All,
I have strange issue, I am trying to find out the duration between two date field on change record and get it in hours.
When I try to run the below code from background script it gives me the accurate result, below is the code snippet
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('number=CHG0055112');
gr.query();
while(gr.next())
{
var start = new GlideDateTime(gr.start_date);
var end = new GlideDateTime(gr.end_date);
var dur_seconds = gs.dateDiff(start, end, true);
var dur_hours = Math.round(dur_seconds / 3600);
gs.print(dur_hours + " Hours");
}
*** Script: 5 Hours
But if I try the similar code from the email script it is giving me 0 hours.
Note: Any duration is less than 24 hours I am getting 0 hours as my output, if number of hours are more than 24 then I am getting the accurate result even from the email script.
Below is my email script:
var start = new GlideDateTime(current.start_date);
var end = new GlideDateTime(current.end_date);
var dur_seconds = gs.dateDiff(start, end, true);
var dur_hours = Math.round(dur_seconds / 3600);
gs.print(dur_hours + " Hours");
Please let me know if I am missing something here