- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 05:09 AM
Hi Dave,
Yes , "Math.round()" then .66 rounded = 1.
Which function should I used to get value decimal format that .66 form.
Thanks,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 06:16 AM
Hi Sourabh
Do you need a specific number of decimals? Otherwise you can just remove the "Math.round()" function.
var dur_seconds = 2400;
var dur_hours = dur_seconds / 3600;
gs.print(dur_hours); // *** Script: 0.6666666666666666
The example above is updated.
Best regards
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 06:47 AM
Possibly parseFloat() - check the Javascript documentation for the Math and Number classes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 08:41 PM
- 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