What It Does

The getValue() method extracts the internal string representation from a GlideDateTime object. ServiceNow stores all datetime values in the database as strings using the ISO-like format yyyy-MM-dd HH:mm:ss, always in UTC timezone. This method returns exactly that internal representation without any timezone conversion or formatting.

When ServiceNow processes this method, it directly accesses the underlying string value stored in the GlideDateTime object's internal state. The platform performs no timezone calculations, no user preference lookups, and no locale-specific formatting. The returned string represents the exact moment in time as stored in UTC, which is how ServiceNow maintains consistency across all timezones.

The method returns null if the GlideDateTime object contains no valid date value, such as when constructed without parameters or when set to an invalid date. It returns an empty string if the GlideDateTime was explicitly set to an empty value using setValue(''). For partially invalid dates, behavior depends on how the GlideDateTime was constructed—some invalid inputs get normalized to valid dates, others result in null.

Edge cases include leap seconds (ignored by ServiceNow), daylight saving transitions (irrelevant since output is UTC), and dates before 1970 or after 2038 on older instances. The method handles future dates correctly but very distant past dates may have platform-specific limitations depending on the underlying Java implementation.

This method complements getDisplayValue() which formats dates for user display, and getNumericValue() which returns milliseconds since epoch. While toString() also returns the internal string, getValue() is the canonical method when you explicitly need the database storage format.

When to Use This

Use getValue() when you need the exact database format for string comparisons, database queries, or integration with external systems that expect UTC timestamps. This is essential for REST API responses, data exports, or when building encoded queries that include datetime comparisons. The method is also crucial when storing datetime values in non-datetime fields or when debugging timezone-related issues.

Avoid using this method when displaying dates to users—use getDisplayValue() instead to respect user timezone and formatting preferences. Don't use getValue() for mathematical date operations—use getNumericValue() to get milliseconds for calculations. The common mistake is using this for user-facing output, which shows UTC times that confuse users expecting their local timezone.

Return Value

Returns a string in the exact format yyyy-MM-dd HH:mm:ss where yyyy is the four-digit year, MM is the two-digit month (01-12), dd is the two-digit day (01-31), HH is the two-digit hour in 24-hour format (00-23), mm is the two-digit minute (00-59), and ss is the two-digit second (00-59). The time is always in UTC regardless of any timezone settings. No timezone indicators like 'Z' or '+00:00' are included in the string.

On failure or invalid dates, the method returns null (not an empty string). Always check for null before using the return value in string operations or concatenations. The safest pattern is var value = gdt.getValue() || ''; to handle null returns gracefully.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

Platform Behavior & Side Effects

  • No Business Rules, ACLs, or notifications fire—this is a read-only operation that accesses existing object data
  • Nothing is written to the database—the method only reads the internal string value from memory
  • Very fast performance as it's a simple string accessor with no timezone calculations or formatting overhead
  • Behavior is identical across all script contexts—before/after Business Rules, Script Includes, Scheduled Jobs
  • No caching mechanisms involved—each call returns the current internal string value of the object
  • System timezone, user timezone preferences, and locale settings have no effect on the returned string
  • Safe to call multiple times on the same object—no side effects or state changes occur