GlideDateTime and nowDateTime?

Singhdeep70
Tera Contributor

What is the difference between GlideDateTime() and gs.nowDateTime()?



Singhdeep70_0-1776844223231.png

 

Singhdeep70_1-1776844246103.png

 

var date = new GlideDateTime();

gs.print(date);
gs.print("Current Date and Time: " + gs.nowDateTime());

Why am I getting different times with this code?
3 REPLIES 3

Tanushree Maiti
Mega Patron

Hi @Singhdeep70 

 

GlideDateTime(): It extends GlideDate to include both date and time components. It offers  date-time operations, such as instantiating a GlideDateTime object, performing date-time calculations, formatting a date-time, or converting between date-time formats.

Refer: SN Doc: GlideDateTime - Global 

Date Time in system TimeZone : new GlideDateTime()

 

gs.nowDateTime(): 

The gs.nowDateTime() method returns the current date and time as a string formatted as yyyy-MM-dd HH:mm:ss.  It does not work in scoped Application. 

Ref: https://thesnowball.co/api/glidesystem/glidesystem-nowdatetime
Date Time in current user’s TimeZone : gs.nowDateTime()

 

 

Best Practice: Ensure that display date and time values are not used in a context where UTC is expected.  You can make this clearer in code by using the getValue()/setValue() and getDisplayValue()/setDisplayValue() methods consistently throughout the code.

 

Refer: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594666

           https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB2121534

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Srikanth_9
Kilo Sage

Hi @Singhdeep70,

 

GlideDateTime() -> It's a server-side API class used to work with date & time object. Works with system time zone & user time zone. 

 

gs.nowDateTime() -> It's a function that returns the current date-time as a formatted string in the instance (system format: yyyy-MM-dd HH:mm:ss).

 

Reference: Problems with using gs.nowDateTime() or GlideDateTime.getDisplayValue() in a GlideDateTime construct....

 

If the provided solution is useful/working, please Accept as Solution and hit the Helpful. 
 
Thanks & Regards,
Srikanth Akula.

SohamTipnis
Mega Sage

Hi @Singhdeep70,

 

  1. GlideDateTime
  • GlideDateTime is an object used to represent date and time values.
  • It can be set to an integer8 date and time, allowing for flexible date-time manipulation.
  • You can also instantiate a new GlideDateTime object by copying the time from another GlideDateTime object

2.     nowDateTime

  • The current date is 2026-04-22.
  • For Pune, Maharashtra, India, the local time can be determined based on Indian Standard Time (IST), but the exact time is not specified in the provided information.
  • The function nowDateTime() returns the current date and time in the user-defined format. 

You can refer to the below information for this:

 

Screenshot 2026-04-22 152714.pngScreenshot 2026-04-22 152807.png

 

 

Let me know if this helps!!😉

 


If you find my answer useful, please mark it as Helpful and Correct. ‌‌‌‌‌‌😊


Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10