What It Does

The getDayOfMonth() method extracts the day component from a GlideDateTime object and returns it as a numeric value between 1 and 31. The calculation is performed in UTC timezone, regardless of the user's session timezone or system timezone settings.

Internally, ServiceNow converts the GlideDateTime's internal millisecond timestamp to a UTC-based Calendar object, then extracts the DAY_OF_MONTH field. This means a datetime of '2024-03-15 23:30:00' will always return 15, even if the user's timezone would display it as the 16th.

The method returns a JavaScript number type, not a string. For invalid or null GlideDateTime objects, it returns NaN. The returned value will never be 0 or greater than 31, as it follows standard calendar month day numbering.

Edge cases include leap year February 29th (returns 29), and months with varying day counts. The method doesn't validate whether the day makes sense for the current month—it simply extracts whatever day component exists in the datetime object.

Related methods include getDayOfMonthLocalTime() which applies timezone conversion, getDayOfWeek() for weekday extraction, and getMonthUTC() for month values. All follow the same UTC-based calculation pattern.

When to Use This

Use getDayOfMonth() when building server-side logic that needs consistent day-of-month values regardless of user timezones. Common scenarios include automated scheduling based on monthly cycles, date range filtering in GlideRecord queries, and business rule conditions that trigger on specific calendar days.

When building user-facing functionality or reports where timezone matters to the user experience, use getDayOfMonthLocalTime() instead. Similarly, for client-side JavaScript, browser Date objects handle timezone conversion automatically.

Avoid using this method for display purposes or when comparing dates entered by users in different timezones. The UTC-based calculation can create confusing results where a user's '15th of the month' entry shows up in logic as the 14th or 16th.

Return Value

Returns a JavaScript number between 1 and 31 representing the day of the month in UTC timezone. The value is always an integer—no decimal places or string formatting are applied.

For invalid GlideDateTime objects or null values, the method returns NaN. Always check for this using isNaN() when the source datetime might be invalid. Direct numeric comparison with NaN always returns false due to JavaScript's NaN behavior.

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 database operations are performed—this is purely a calculation method that reads from the GlideDateTime object in memory
  • No Business Rules, ACLs, or notifications are triggered since this method only reads existing datetime data
  • Performance is very fast—minimal CPU overhead for the UTC calendar calculation with no caching needed
  • Behaves identically in before/after Business Rules, Script Includes, and Scheduled Jobs—no execution context dependencies
  • Does not respect user session settings or preferences—always uses system UTC timezone for calculation
  • Multiple calls on the same GlideDateTime object return identical results—the underlying datetime value is not modified
  • Thread-safe for concurrent execution in scheduled jobs or high-volume Business Rules