- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 06:33 PM
I need to be able to convert a value from a catalog item field to a datetime to compare it to the current date. The problem is that GlideDateTime does not seem to recognize PM times, even though the API Docs say that GlideDateTime supports AM/PM timezones (e.g. dd.MM.yyyy hh:mm:ss a).
For instance:
gs.info(new GlideDateTime('2022-01-01 08:00:00 PM'));
gs.info(new GlideDateTime('01/01/2022 08:00:00 PM'));
// this code prints "2022-01-01 08:00:00", but it should print "2022-01-01 20:00:00"
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 01:23 PM
I solved this by using getValue() in the client script, and GlideDateTime's .setDisplayValue method to create the GlideDateTime object with that display value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 07:02 PM
Hi
internally GlideDateTime is already in 24-hours format.
Try
gs.info(new GlideDateTime('01/01/2022 20:00:00'));
Kind regards
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 07:13 PM
>though the API Docs say that GlideDateTime supports AM/PM timezones (e.g. dd.MM.yyyy hh:mm:ss a).
Where is in the docs?
I can only find the following in both global and scoped.
GlideDateTime(String value)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 07:39 PM
If the question is referring to the below, the argument is in GlideDateTime format and not String.
GlideDateTime(GlideDateTime gdt)
The system attempts to match the argument passed to the gdt parameter with the specified internal system format. If the argument does not match the system format, the system attempts to match it to one of the following formats in this order:
- yyyy-MM-dd'T'HH:mm:ss.SSSZ
- MM/dd/yyyy HH:mm:ss
- MM-dd-yyyy HH:mm:ss
- MM-dd-yyyy HH:mm
- MM-dd-yyyy
- MM/dd/yy HH:mm:ss
- MM/dd/yyyy
- dd-MM-yyyy HH:mm:ss
- dd-MM-yyyy HH.mm.ss
- dd-MM-yyyy HH.mm
- dd-MM-yy HH:mm:ss
- dd-MM-yy HH.mm.ss
- dd/MM/yyyy
- dd-MM-yyyy
- yyyy-MM-dd HH:mm
- yyyy-MM-dd
- dd.MM.yyyy HH:mm:ss
- dd.MM.yyyy HH.mm.ss
- dd.MM.yyyy hh:mm:ss a
- dd.MM.yyyy hh.mm.ss a
- dd.MM.yyyy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 07:57 PM
JavaScript's Date does support AM/PM so the following will create a GlideDateTime
var d = new Date('01/01/2022 08:00:00 PM');
gs.info(d);
var gdt = new GlideDateTime(d);
gs.info(gdt);
Result. Note that Date() is returning date in PST timezone and GlideDateTime() expects date/time in UTC.
*** Script: Sat Jan 01 2022 20:00:00 GMT-0800 (PST)
*** Script: 2022-01-02 04:00:00