Skip to content

Commit c7b59e5

Browse files
authored
readme.md
1 parent c8f303f commit c7b59e5

File tree

1 file changed

+21
-0
lines changed
  • Core ServiceNow APIs/GlideDateTime/Convert UTC Time To Local Time

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Overview
2+
This script converts a UTC date/time field in ServiceNow to the local time of the user that the script runs under using GlideDateTime.
3+
This distinction is important in certain contexts, such as asynchronous business rules, scheduled jobs, or background scripts, where the executing user may differ from the record owner.
4+
It is useful for notifications, reports, dashboards, or any situation where users need localized timestamps that reflect the correct timezone.
5+
6+
## Table and Field Example
7+
Table: incident
8+
Field: opened_at (stored in UTC)
9+
10+
## How It Works
11+
The script queries the incident table for the most recent active incident.
12+
Retrieves the opened_at field (in UTC).
13+
Creates a GlideDateTime object to convert this UTC timestamp into the local time of the executing user.
14+
Logs both the original UTC time and the converted local time.
15+
16+
## Key Notes
17+
Conversion is always based on the timezone of the user executing the script.
18+
In asynchronous operations (background scripts, scheduled jobs, async business rules), this is the system user running the script.
19+
20+
## Reference
21+
https://developer.servicenow.com/dev.do#!/reference/api/zurich/server_legacy/c_GlideDateTimeAPI

0 commit comments

Comments
 (0)