Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Overview
This script converts a UTC date/time field in ServiceNow to the **user's local time** using **GlideDateTime**.
Useful for notifications, reports, dashboards, or any situation where users need **localized timestamps**.

## Table and Field Example
- **Table:** `incident`
- **Field:** `opened_at` (stored in UTC)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function() {
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.orderByDesc('opened_at');
gr.setLimit(1); // Example: take the latest active incident
gr.query();

if (gr.next()) {
// GlideDateTime object from UTC field
var utcDateTime = gr.opened_at;

// Convert to user's local time zone
var localTime = new GlideDateTime(utcDateTime);
var displayValue = localTime.getDisplayValue(); // Returns local time in user's timezone

gs.info('UTC Time: ' + utcDateTime);
gs.info('Local Time: ' + displayValue);
} else {
gs.info('No active incidents found.');
}
})();
Loading