Global date and time field format
Summarize
Summary of Global date and time field format
This functionality allows ServiceNow administrators to define default global formats for date and time fields using system properties. These global settings ensure consistency across the platform, while still allowing individual users to override them with personal preferences.
Show less
Configuring Date Format
- The glide.sys.dateformat system property controls the global date format and can be modified via System Properties > System.
- The default date format is
yyyy-MM-dd. - It is recommended to use a four-digit year format (e.g.,
yyyy) to prevent issues with year interpretation that can cause unexpected behavior when using two-digit year formats. - Date format patterns follow the
java.text.SimpleDateFormatclass conventions, except that the time zone character'z'cannot be appended in scripts due to validation errors. - Key format abbreviations include:
- Year: yyyy (4 digits), yy or y (2 digits)
- Month: MMM (name), MM (2 digits), M (1-2 digits)
- Day: dd (2 digits), d (1-2 digits)
- After modifying the date format, it is important to validate the new format using the "Validate date and time" script to ensure correctness.
Configuring Time Format
- The glide.sys.timeformat system property controls the global time format and can be modified via System Properties > System.
- The default time format is
HH:mm:ss(24-hour format with hours, minutes, and seconds). - Time format patterns also follow
java.text.SimpleDateFormatconventions, with the same restriction on the'z'character for time zones. - Key format abbreviations include:
- Hour: hh/h (1-12 hour), HH/H (0-23 hour)
- Minute: mm/m
- Second: ss/s
- AM/PM indicator: Add
aat the end of the format string to display AM or PM, applicable for both 12-hour and 24-hour formats.
- Changes should also be validated using the "Validate date and time" script to avoid errors.
User Personalization
- Individual users can personalize how date and time values appear within their sessions, overriding the global default formats.
- This personalization allows users to tailor display formats to their preferences without affecting system-wide settings.
Practical Considerations
- Always validate any changes to date and time formats with the provided validation script to prevent invalid date/time errors.
- Avoid using two-digit year formats to prevent misinterpretation of dates decades in the past or future.
- Do not use the time zone character
'z'in format strings within scripts, as this causes validation failures.
You define default date and time formats globally using system properties.
Date format
The glide.sys.date_format property defines the date format. An administrator can modify the property by navigating to . The default format is: yyyy-MM-dd.
- You cannot append the 'z' character to include the time zone when adding it to a script.
- If the resulting time zone is not three characters, an Invalid Date appears error appears when you validate the script, because the Date/Time Validation Script (sys_script_validator) fails. This failure occurs even though the script debugger shows that the content of the value meets the requirement of 'g_user_date_time_format'.
| Field | Full form | Short form |
|---|---|---|
| Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits) |
| Month | MMM (name or abbr.) | MM (2 digits), M (1 or 2 digits) |
| Day of Month | dd (2 digits) | d (1 or 2 digits) |
- If your system date format is set to use the yy year format, the system considers dates 20 years later or 80 years earlier from the current date as a date in the past or future leading to an unexpected behavior.
- For example, if you set the year as 51 for 2051, the system considers the year as 1951. Similarly, if you set the year as 37 for 1937, the system considers the year as 2037.
Time format
An administrator can modify the glide.sys.time_format property by navigating to . Modifying the property changes the date or time format globally. When modifying the standard time format, also verify the format using a Validate date and time script. You can use the same pattern strings as the java.text.SimpleDateFormat class, with the following exception: Appending 'z' to include the time zone is not supported.
The format string consists of the following abbreviations.
| Field | Full form | Short form |
|---|---|---|
| Hour (1-12) | hh (2 digits) | h (1 or 2 digits) |
| Hour (0-23) | HH (2 digits) | H (1 or 2 digits) |
| Minute | mm (2 digits) | m (1 or 2 digits) |
| Second | ss (2 digits) | s (1 or 2 digits) |
Add the character a to the end of the time format string to indicate AM or PM. This option shows AM or PM whether you are using 12-hour time (hh) or 24-hour time (HH).
The default format is: HH:mm:ss.