Difference between start created date time and updated date time
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 01:56 AM
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 02:05 AM
var grInc = new GlideRecord('incident');
grInc.addQuery('number', ' ' ); //query with Incident no.
grInc.query();
if(grInc.next()){
var created_date_time = new GlideDateTime(grInc.sys_created_on);
var updated_date_time = new GlideDateTime(grInc.sys_updated_on);
var dur_seconds = gs.dateDiff(updated_date_time, created_date_time, true);
var dur_hours = Math.round(dur_seconds / 3600);
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 03:02 AM
HI @Mark Wood ,
I trust you are doing great.
Please try below code :
// Assuming you have the created and updated dates stored in variables
var createdDate = new GlideDateTime('yyyy-MM-dd HH:mm:ss'); // Replace with the actual created date
var updatedDate = new GlideDateTime('yyyy-MM-dd HH:mm:ss'); // Replace with the actual updated date
// Calculate the difference in milliseconds
var differenceInMs = updatedDate.getNumericValue() - createdDate.getNumericValue();
// Convert the difference to hours
var differenceInHours = differenceInMs / (1000 * 60 * 60);
// Display the result
gs.info('The difference in hours is: ' + differenceInHours);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi