What It Does
The getNumericValue() method converts a GlideDateTime object into its numeric representation as milliseconds since the Unix epoch (00:00:00 UTC on January 1, 1970). ServiceNow internally stores all datetime values as milliseconds from this epoch, and this method exposes that raw numeric value for mathematical operations.
When called, ServiceNow retrieves the internal timestamp representation and returns it as a JavaScript number. This conversion happens immediately without database queries or timezone calculations—the method simply exposes the already-stored millisecond value that ServiceNow uses internally for all datetime storage and comparison operations.
The method returns a positive integer for any date after January 1, 1970, and a negative integer for dates before the epoch. For invalid or uninitialized GlideDateTime objects, it returns 0, which represents the epoch itself rather than indicating an error condition.
The numeric value accounts for timezone information stored in the GlideDateTime object. If the datetime was created with a specific timezone, the numeric value represents the UTC equivalent of that local time. This differs from getValue() which returns a formatted string, and getDisplayValue() which applies user timezone preferences for display.
Unlike string-based datetime methods that can fail parsing or return empty strings, getNumericValue() always returns a number, making it reliable for mathematical calculations. The relationship to setNumericValue() is complementary—you can extract a numeric value with this method and later restore it using the setter on another GlideDateTime instance.
When to Use This
Use getNumericValue() when you need to perform mathematical operations on dates—calculating durations, finding time differences, or comparing dates numerically. This is the most efficient method for duration calculations because you can subtract two numeric values directly without string parsing or complex date arithmetic.
For simple date comparisons without calculations, use before() or after() methods instead—they're more readable and handle edge cases better.
Avoid using this method when you need formatted output for users or when storing datetime values as strings in fields. Use getDisplayValue() for user-facing display or getValue() for database storage. Common misuse includes converting to numeric values just to compare dates—ServiceNow can compare GlideDateTime objects directly without numeric conversion.
Return Value
Returns a JavaScript number representing milliseconds since the Unix epoch. Positive numbers represent dates after January 1, 1970 00:00:00 UTC, while negative numbers represent dates before the epoch. The precision includes milliseconds, though ServiceNow typically stores datetime values with second-level precision.
For uninitialized or invalid GlideDateTime objects, the method returns 0, which corresponds to the Unix epoch itself. Always validate that your GlideDateTime is properly initialized before using the numeric value in calculations, since 0 is both a valid timestamp (the epoch) and the default for invalid objects.
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 database queries are executed—the method reads from the already-loaded GlideDateTime object in memory
- No Business Rules, ACLs, or notifications are triggered since this is a read-only operation
- Extremely fast performance—numeric conversion is cached internally and doesn't require timezone calculations
- Behaves identically in all script contexts—before/after Business Rules, Script Includes, Scheduled Jobs
- Returns the same value regardless of the current user's timezone preferences or session settings
- No side effects on the original GlideDateTime object—the object remains unchanged after calling this method
- Thread-safe for concurrent access since it only reads existing data without modification