
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 05:17 AM
I'm trying to convert the delivery_time field from a catalogue item to the number of seconds, but I'm going round in circles with GlideDuration and GlideDateTime values. I know the underlying storage of a GlideDuration object is either seconds or milliseconds. How do I get to that value?
I've tried the following in background scripts:
var a = new GlideRecord('sc_cat_item');
a.get("0d68ec6edb5c070039f7f70dbf96191d");
gs.print(a.delivery_time.toString());
var b = new GlideDateTime(a.delivery_time.toString());
gs.print(b);
var c = new GlideDuration(0);
gs.print(c.toString());
var d = GlideDateTime.subtract(c, b);
gs.print(d.toString());
Which gives me:
*** Script: 1970-01-03 00:00:00
*** Script: 1970-01-03 00:00:00
*** Script: 1970-01-01 00:00:00
*** Script: 1970-01-03 00:00:00
But I'm going round in circles
Been referring to this - https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_ScopedGlideDurationGlideDuration_St...
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 05:22 AM
Hi Peter,
Use the GlideDuration method getByFormat() to format it in to YYYY-MM-dd hh:mm:ss
and then you can feed that to GlideDateTime() and use getNumericValue() to get the number seconds (since 1970).
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_ScopedGlideDateTimeGetNumericValue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 05:14 PM
Another quick note, use YYYY-MM-dd HH:mm:ss with uppercase HH. hh uses 12 hour (1-12) intervals to distinguish AM and PM. HH uses 24 hour cycle (0-23)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2025 11:24 PM
Good to mention!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 06:12 AM
Hi Peter,
I was trying this in my instance and get this (in milliseconds) using the below script.
var a = new GlideRecord('sc_cat_item');
a.get("10b44eb6c6112276005acf13b5c13274");
gs.print(a.sys_updated_on);
var b = new GlideDateTime(a.sys_updated_on);
gs.print(b.getNumericValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2021 12:05 PM
For anyone else struggling with a similar issue, here's the code I used to add the time in a duration field to the start date/time and then populate the end date/time via a before insert/update business rule. The .getValue() function was crucial.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
// calculates the end time of an activity based on the start time and duration
var startTime = new GlideDateTime(current.variables.access_start.getValue()); // getting start time
var dur = new GlideDateTime(current.variables.how_long.getValue()); // getting duration and converting to GlideDateTime
dur = dur.getNumericValue()/1000; // calculating the total duration in seconds
//gs.addInfoMessage(dur);
startTime.addSeconds(dur); // add the seconds to the start time to calculate end time
current.variables.access_end = startTime.getValue(); // set the end time
gs.addInfoMessage("End time automatically adjusted based on start time and duration");
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2021 06:17 AM