- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 11:22 AM
g_form.getValue('start_date') returns "03/31/2022 01:00:00 PM" and this is causing issues when I pass that value to a script include for verification against other dates. I am in CST, so the UTC value that the script include uses should be "2022-03-31 18:00:00". Can I achieve this easily with GlideDateTime or another API or do I have to figure out how to manually re format that date?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 06:10 PM
Hi,
When you pass this "display value" to your script include, you'd want to use a GlideDateTime object within the SI and set the display value of that object to the display value brought over from your GlideAjax.
Then, you can use the server value (.getValue()) as needed within that GlideDateTime object which will give you it's UTC.
There's no need for any conversion, long scripts, etc.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 06:14 PM
I've posted a client script to convert the date/time to UTC but the common way is to just pass the numeric value of date/time in the client script to Script Include.
e.g. client script parameter to pass to script include.
ajax.addParam('sysparm_datetime', getDateFromFormat(newValue, g_user_date_time_format));
Then in the Script Include
var dateTimeNum = this.getParameter('sysparm_datetime');
dateTimeNum = parseInt(dateTimeNum);
var d = new Date(dateTimeNum);
var gdt = new GlideDateTime(d);
gs.info(gdt.getValue()); // this will be in internal date/time format in UTC

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 12:18 PM
Hi. If your issue is resolved and my response has helped, plese consider marking Correct and Helpful. Thanks!
Martin Ivanov
2022 Community Rising Star
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Another answer marked as correct, when it does not answer the question. And also linking to missing content (SN redirect laziness when migrating to another site).
There is clearly a fault in SN's DateTime component on the portal, as it should not be returning the DisplayValue, as this also causes issues in order guides, and trying to pass a date field, into a Date/Time field like due_date.