- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 06:05 AM
1970-01-02 00:30:55
1 Day 30 Minutes
00:30:55
1 00:30:55
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 07:28 AM - edited 08-07-2024 09:20 AM
There's probably a more elegant way of doing this, but here is a way to get your desired results:
var pastDate = new GlideDateTime("2020-04-16 20:00:00");
var currDate = new GlideDateTime("2020-04-17 21:30:55");
var dur1 = GlideDateTime.subtract(pastDate,currDate);
var hrsDiff = Math.floor((currDate.getNumericValue() - pastDate.getNumericValue()) / (60 * 60 * 1000));
gs.print(hrsDiff + ':' + dur1.getByFormat('mm:ss'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 12:31 PM
Hello @Hemakumar J ,
// Define the two dates
var pastDate = new GlideDateTime("2020-04-16 20:00:00");
var currDate = new GlideDateTime("2020-04-17 20:30:55");
// Calculate the difference in milliseconds
var diffInMilliseconds = currDate.getNumericValue() - pastDate.getNumericValue();
// Convert milliseconds to seconds
var diffInSeconds = Math.floor(diffInMilliseconds / 1000);
// Convert seconds to hours, minutes, and seconds
var hours = Math.floor(diffInSeconds / 3600);
var minutes = Math.floor((diffInSeconds % 3600) / 60);
var seconds = diffInSeconds % 60;
// Format as HH:mm:ss
var formattedDuration = (hours < 10 ? '0' : '') + hours + ':' +
(minutes < 10 ? '0' : '') + minutes + ':' +
(seconds < 10 ? '0' : '') + seconds;
// Output the formatted duration
gs.info(formattedDuration);
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 12:31 PM
Hello @Hemakumar J ,
// Define the two dates
var pastDate = new GlideDateTime("2020-04-16 20:00:00");
var currDate = new GlideDateTime("2020-04-17 20:30:55");
// Calculate the difference in milliseconds
var diffInMilliseconds = currDate.getNumericValue() - pastDate.getNumericValue();
// Convert milliseconds to seconds
var diffInSeconds = Math.floor(diffInMilliseconds / 1000);
// Convert seconds to hours, minutes, and seconds
var hours = Math.floor(diffInSeconds / 3600);
var minutes = Math.floor((diffInSeconds % 3600) / 60);
var seconds = diffInSeconds % 60;
// Format as HH:mm:ss
var formattedDuration = (hours < 10 ? '0' : '') + hours + ':' +
(minutes < 10 ? '0' : '') + minutes + ':' +
(seconds < 10 ? '0' : '') + seconds;
// Output the formatted duration
gs.info(formattedDuration);
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!