GlideDateTime and nowDateTime?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
What is the difference between GlideDateTime() and gs.nowDateTime()?
var date = new GlideDateTime();
Why am I getting different times with this code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Singhdeep70,
- 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:
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
