What It Does
The addSeconds() method performs arithmetic on a GlideDateTime object by adding the specified number of seconds to its current timestamp. The method modifies the original GlideDateTime object directly rather than creating a new instance, which means the change is permanent to that object reference.
Internally, ServiceNow converts the GlideDateTime to milliseconds since epoch, adds the specified seconds (converted to milliseconds), and updates the internal timestamp. This ensures precision and handles timezone calculations automatically based on the current user's timezone settings or the system timezone if called from a system context.
The method returns void, meaning it doesn't provide a return value. The operation either succeeds by modifying the GlideDateTime object or fails silently if given invalid input. When passed a non-numeric value, the method treats it as 0 and makes no change to the timestamp.
Edge cases include passing extremely large numbers that could cause integer overflow, though ServiceNow's Java backend typically handles this gracefully. The method accepts negative values naturally, making it effectively both an add and subtract operation. Fractional seconds are truncated to integers, so passing 1.7 adds exactly 1 second.
This method is part of a family of similar arithmetic methods including addDays(), addMonths(), and addYears(). Unlike those methods which must account for variable month lengths and leap years, addSeconds() provides the most predictable behavior since seconds are fixed units.
When to Use This
Use addSeconds() when you need precise time calculations involving seconds, such as adding timeout periods, calculating SLA deadlines with second-level precision, or implementing time-based business logic that requires exact intervals. It's particularly useful for workflow timeouts, session expiration calculations, and API rate limiting scenarios where second precision matters.
For larger time periods, use addDays() or addMonths() instead, as they handle daylight saving time transitions and month boundaries more appropriately. Avoid using addSeconds(86400) to add a day, since this won't account for DST changes that make some days 23 or 25 hours long.
Common misuse includes trying to chain the method calls expecting a return value, or using it for date formatting. The method modifies the object in place, so save a copy first if you need the original timestamp. Don't use this method if you need the result as a new GlideDateTime object without modifying the original.
Return Value
The method returns void (undefined in JavaScript), which means it provides no return value. The operation's success is reflected in the modified state of the GlideDateTime object itself. There's no failure indicator - invalid inputs are silently ignored and the timestamp remains unchanged.
Since there's no return value, you cannot chain method calls or use the result in expressions. Always call the method as a standalone statement, then use the modified GlideDateTime object in subsequent operations. Check the object's value using getValue() or getDisplayValue() to confirm the change took effect.
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 fire - this is purely an in-memory object manipulation
- Nothing is written to the database until you assign the modified GlideDateTime to a record field and save
- Performance is very fast - it's a simple arithmetic operation on the internal timestamp
- Works identically across all server-side contexts (Business Rules, Script Includes, Scheduled Jobs)
- Timezone handling respects the current user's timezone in UI contexts, system timezone in background jobs
- No caching involved - each call recalculates the timestamp immediately
- Memory usage is minimal - modifies existing object rather than creating new instances