Perform date arithmetic, time calculations, and schedule management using server-side APIs. Covers GlideDateTime, GlideDate, GlideDuration, and scheduling operations. Use when handling date calculations, working with timezones, managing scheduled tasks, or implementing time-based business logic.
Resources
1Install
npx skillscat add danielmadsendk/nowdev-ai-toolbox/servicenow-server-date-time Install via the SkillsCat registry.
SKILL.md
Server Date & Time
Quick start
GlideDateTime (core API):
// Current time
var now = new GlideDateTime();
gs.info(now.getDisplayValue()); // 2026-02-06 14:30:45
// Add/subtract time
var future = new GlideDateTime();
future.addDays(7);
future.addHours(2);
// Compare dates
var start = new GlideDateTime('2026-02-01');
var end = new GlideDateTime('2026-02-28');
var diff = GlideDateTime.getDifference(start, end);
gs.info(diff.getDisplayValue()); // Shows durationGlideDate (date only, no time):
var today = new GlideDate();
gs.info(today.getDisplayValue()); // 2026-02-06
var nextMonth = new GlideDate('2026-03-06');GlideDuration (time spans):
var duration = new GlideDuration('PT8H30M'); // 8 hours 30 minutes
gs.info(duration.getDisplayValue()); // 08:30:00Schedule operations:
var schedule = new GlideSchedule('9-to-5', 'UTC');
var isAvailable = schedule.isInSchedule(new GlideDateTime());
// Add schedule segments
schedule.add(new GlideDateTime('2026-02-06 09:00:00'),
new GlideDateTime('2026-02-06 17:00:00'));Recurring schedules:
var recurring = new GlideMultiRecurrence();
// Configure based on sys_trigger table fields
// Returns array of GlideDateTime objects for next occurrencesUtilities
DateTimeUtils (script include):
// Various utility functions
var utils = new DateTimeUtils();
var nextWeek = utils.addDays(now, 7);DurationCalculator (script include):
var calc = new DurationCalculator();
var dueDate = calc.calculateDueDate(startDate, duration);Best practices
- Always use GlideDateTime for timezone-safe operations
- Avoid JavaScript Date objects for ServiceNow data
- Use GlideSchedule for business hours calculations
- Store dates in UTC internally; format for display only
- Use GlideDuration for time spans and calculations
- Test date calculations with different timezones
- Remember: GlideDateTime automatically handles DST
- Use appropriate granularity (Date vs DateTime vs Time)
- Consider user timezone when displaying dates
Key APIs
| API | Purpose |
|---|---|
| GlideDateTime | Date and time with timezone support |
| GlideDate | Date only, no time component |
| GlideDuration | Time spans and durations |
| GlideTime | Time only, no date |
| GlideSchedule | Business hour calculations |
| GlideMultiRecurrence | Recurring schedule occurrences |
Reference
For timezone handling, DST considerations, and advanced patterns, see BEST_PRACTICES.md