- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have several locations where I am calculating a duration and then using that value later. When I calculate the value based on the difference in two date time fields, it shows up correctly and displays correctly. When I calculate based on what is showing in the duration field I get an entirely different value.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@mheyman ,
Duration field stores its value internally as a timestamp relative to the Unix epoch (e.g...... since 1970-01-01 00:00:00) rather than a simple raw difference, so if you try to build a GlideDuration from that stored value and then call getByFormat() you’ll often see unexpected results..... whereas calculating the difference between two GlideDateTime objects (e.g..... using GlideDateTime.subtract(start, end)) or using their numeric values gives you the correct duration value to work with in your script.........
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Technical Consultant - Rising Star/Class of Legends 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@mheyman ,
Duration field stores its value internally as a timestamp relative to the Unix epoch (e.g...... since 1970-01-01 00:00:00) rather than a simple raw difference, so if you try to build a GlideDuration from that stored value and then call getByFormat() you’ll often see unexpected results..... whereas calculating the difference between two GlideDateTime objects (e.g..... using GlideDateTime.subtract(start, end)) or using their numeric values gives you the correct duration value to work with in your script.........
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Technical Consultant - Rising Star/Class of Legends 2025