What It Does
The nowDateTime() method returns the current date and time as a string formatted as yyyy-MM-dd HH:mm:ss. The timestamp reflects the exact moment when the method executes, using the ServiceNow instance's configured timezone.
Internally, ServiceNow calls the Java System.currentTimeMillis() method to get the current time in UTC, then converts it to the instance timezone and formats it as a string. This conversion happens every time you call the method, so multiple calls within the same transaction will show slightly different timestamps.
The method always returns a valid string and never returns null or an empty value. The timestamp precision goes down to the second level – milliseconds are truncated, not rounded. If you need millisecond precision, use gs.now() which returns a GlideDateTime object.
During daylight saving time transitions, the method respects the instance timezone rules. When clocks "fall back" and create an ambiguous hour, ServiceNow uses the standard time interpretation. When clocks "spring forward" and skip an hour, the method returns the adjusted time without the skipped hour.
This method is closely related to gs.now() and gs.nowNoTZ(). While gs.now() returns a GlideDateTime object and gs.nowNoTZ() returns UTC time, nowDateTime() provides the middle ground of a simple string in instance timezone.
When to Use This
Use nowDateTime() when you need a human-readable timestamp for logging, debugging messages, or simple date comparisons where timezone conversion isn't critical. It's perfect for adding timestamps to custom log entries, creating simple audit trails, or generating basic date-based identifiers.
Avoid this method when working with datetime fields in records, performing date arithmetic, or handling user-specific timezones. For those scenarios, use gs.now() which returns a GlideDateTime object with full timezone awareness and date manipulation methods. Don't use it for storing in the database – ServiceNow expects GlideDateTime objects for datetime fields.
Never use nowDateTime() to populate datetime fields on records. The string format doesn't include timezone information, leading to incorrect values in the database.
Return Value
Returns a string in the exact format yyyy-MM-dd HH:mm:ss, where months, days, hours, minutes, and seconds are zero-padded to two digits. The year is always four digits. The format never varies regardless of user preferences or locale settings – it uses the ISO-style format consistently.
The method never fails and always returns a valid timestamp string. You can safely use the return value in string operations, comparisons, or logging without null checks. The string is directly comparable with other timestamps from the same method using standard string comparison, as long as they're in the same timezone.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- No Business Rules, ACLs, or notifications are triggered – this is a pure read operation
- Nothing is written to the database – the method only reads system time
- Extremely fast execution with no caching needed since time is always current
- Behaves identically in before/after Business Rules, Script Includes, and Scheduled Jobs
- Each call returns a slightly different timestamp due to execution time differences
- Uses the instance timezone setting, not the user's personal timezone preference
- No impact on transaction rollback behavior since no database changes occur