- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 12:02 AM
for below code
var dur = GlideDateTime.subtract(new GlideDateTime("2025-03-28 18:04:55"), new GlideDateTime("2025-03-29 18:04:55"));
gs.info("dur: " +dur.getByFormat('hh:mm:ss'));
dur_seconds = GlideDateTime.subtract(new GlideDateTime("2025-03-28 18:04:55"), new GlideDateTime("2025-03-28 18:04:55"));
gs.info("dur: "+dur.getByFormat('hh:mm:ss'));
expect first print 24:00:00, and second to be 00:00:00, but both print
12:00:00
is this correct? confused
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 01:49 AM
ooh, can try with Convert the duration to seconds and then format manually.
var dur = GlideDateTime.subtract(new GlideDateTime("2025-03-28 18:04:55"), new GlideDateTime("2025-03-29 18:04:55"));
var totalSeconds = dur.getDurationValue();
var hours = Math.floor(totalSeconds / 3600); // Get hours
var minutes = Math.floor((totalSeconds % 3600) / 60); // minutes
var seconds = totalSeconds % 60; //seconds
gs.info("dur: " + (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 12:25 AM
Hi @Chris45
You need to modify your script as below.
var dur = GlideDateTime.subtract(new GlideDateTime("2025-03-28 18:04:55"), new GlideDateTime("2025-03-29 18:04:55"));
gs.info(dur.getDisplayValue());
gs.info(dur.getByFormat('hh:mm:ss'));
var dur_seconds = GlideDateTime.subtract(new GlideDateTime("2025-03-28 18:04:55"), new GlideDateTime("2025-03-28 18:04:55"));
gs.info(dur_seconds.getDisplayValue());
gs.info(dur_seconds.getByFormat('hh:mm:ss'));
Output:
Explanation:
Since you are using "hh:mm:ss", the system will gives you the output in 12 hours format.
if you convert 24 hours -> 12 hours format, then the output should be 12 because in 12 hours format a day starts at 12 and ends at 12.
The same applies for 0 seconds, in 12 hours format, 12 will be consdierd as 0 as well as 24.
Hope this helps.
Regards,
Siva