- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2020 07:33 AM
Hi, I am trying to get the Duration based on the difference between two GlideDateTimes. Getting the display value from the GlideDateTime does not seem to be pulling AM/PM or converting it to a 24-hour format for my calculation. My script is below. Is there something I am missing from this script to get the GlideDateTime in 24-hour format?
Thanks in advance
(function executeRule(current, previous /*null when async*/) {
var actualstart = new GlideDateTime(current.u_diagnosis_time.getDisplayValue());
var actualfinish = new GlideDateTime(current.u_repair_time.getDisplayValue());
//If the begin and end times are present, calculate the duration
if (actualstart && actualfinish) {
// var difference = gs.dateDiff(actualstart, actualfinish, false);
var difference = GlideDateTime.subtract(actualstart, actualfinish);
current.u_dttrt.setValue(difference);
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2020 07:44 AM
Date/Time fields are stored in 24-hour format, it's the display preference that can make it am/pm, so I would just use:
var actualstart = new GlideDateTime(current.u_diagnosis_time);
var actualfinish = new GlideDateTime(current.u_repair_time);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2020 07:44 AM
Date/Time fields are stored in 24-hour format, it's the display preference that can make it am/pm, so I would just use:
var actualstart = new GlideDateTime(current.u_diagnosis_time);
var actualfinish = new GlideDateTime(current.u_repair_time);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2020 08:10 AM
Thanks for the help Brad that solved my issue. The getDisplayValue() was unnecessary

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2021 07:53 AM
This is not working for me.
var start = "2021-06-28 08:00:00 PM";
var startdate = new GlideDateTime(start);
gs.print(startdate);
I get this:
*** Script: 2021-06-28 08:00:00

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2021 07:57 AM
I figured it out...
***
var start = "2021-06-28 08:00:00 PM";
var startdate = new GlideDateTime();
startdate.setDisplayValue(start, 'yyyy-mm-dd hh:mm:ss');
gs.print(startdate);