Date and Time Help

SandeepKSingh
Kilo Sage

In ServiceNow, g_form.getValue() returns the user’s display value for a Date/Time field. How can I retrieve the actual system (UTC) value of that field inside a Script Include?”

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hi @SandeepKSingh 

When you pass a display value into your Script Include, you should wrap it in a GlideDateTime object. Set that object’s display value to the one you received from the GlideAjax call.

Once the display value is set, you can safely use the server value (.getValue()) from the GlideDateTime object, which will return the UTC time.

This approach removes the need for manual conversions or lengthy scripts—the platform handles the conversion for you.

Using .getValue() would get you the server value, which is stored in UTC.

Using .getDisplayValue() would get you the display value of the field, which is set to your preference and timezone.




https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/c_APIRef#r_ScopedGl...

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

1 REPLY 1

Ravi Gaurav
Giga Sage
Giga Sage

Hi @SandeepKSingh 

When you pass a display value into your Script Include, you should wrap it in a GlideDateTime object. Set that object’s display value to the one you received from the GlideAjax call.

Once the display value is set, you can safely use the server value (.getValue()) from the GlideDateTime object, which will return the UTC time.

This approach removes the need for manual conversions or lengthy scripts—the platform handles the conversion for you.

Using .getValue() would get you the server value, which is stored in UTC.

Using .getDisplayValue() would get you the display value of the field, which is set to your preference and timezone.




https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/c_APIRef#r_ScopedGl...

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/