What It Does
The addDays() method performs date arithmetic by adding the specified number of days to the current GlideDateTime object. The method modifies the existing object rather than returning a new one, making it a destructive operation that permanently changes the date value stored in the object.
Internally, ServiceNow converts the GlideDateTime to milliseconds since epoch, adds the day value (converted to milliseconds), then reconstructs the date object. This approach ensures accurate handling of daylight saving time transitions, leap years, and varying month lengths without requiring manual calendar logic.
The method returns void (undefined in JavaScript), not the modified GlideDateTime object. This prevents method chaining after addDays() and distinguishes it from immutable date libraries that return new objects.
Edge cases include negative day values (which subtract days), fractional day values (truncated to integers), and very large values that could cause integer overflow. The method handles month boundary crossings automatically—adding 5 days to January 28th correctly results in February 2nd, accounting for the actual number of days in January.
Related methods include addMonths(), addYears(), and addSeconds(). Unlike addMonths() which can produce ambiguous results (adding a month to January 31st), addDays() always produces predictable, unambiguous results.
When to Use This
Use addDays() for business logic that requires precise day-based calculations: SLA due dates, escalation timelines, recurring maintenance windows, or any scenario where you need to move forward or backward by a specific number of calendar days. It's particularly valuable for workflows that span weekends or month boundaries.
Avoid addDays() for business-day calculations that should skip weekends—use addBusinessDays() instead. For time-sensitive operations requiring hour or minute precision, use addSeconds() with appropriate multipliers. Don't use this method if you need the original date preserved—create a copy with new GlideDateTime(originalDate) first.
Return Value
The method returns void (JavaScript undefined), not the modified GlideDateTime object. The modification happens in place on the original object, so the date value changes but no new object is created. This is different from many modern JavaScript date libraries that return new instances.
Since the method modifies the existing object, continue using the original GlideDateTime variable after calling addDays(). The method cannot fail in ways that return error values—invalid parameters are handled through standard JavaScript type coercion (non-numeric values become NaN, which adds zero days).
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 since this is a client-side object manipulation, not a database operation
- Nothing is written to the database until you explicitly update a GlideRecord field with the modified GlideDateTime
- Performance is fast—simple arithmetic operation with no database queries or external system calls
- Timezone calculations are handled automatically based on the GlideDateTime's existing timezone context
- Behavior is identical across Business Rules, Script Includes, and Scheduled Jobs—no context-dependent variations
- Memory footprint is minimal since no new objects are created, just modification of existing date values