- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 07:57 AM
I am in GMT time zone and moved forward 1 hour to daylight savings time yesterday, so instance time is now UTC+1.
Using the following...
...(where starttimestring=2025-04-02 19:00:00) in Planned Start Date field in Create Change Request Record in a flow, set the field correctly to 02/04/2025 19:00:00 before daylight savings time change, but now sets the field to 02/04/2025 20:00:00. System log shows 'starttime: 2025-04-02 19:00:00'.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 08:51 AM - edited 04-01-2025 08:14 AM
Hello @Scott Eaglesham ,
It depends a bit on which time zone you mean when you say "local time". A fixed time zone (yours, GMT), or the local time zone of the user who triggers the flow?
In the first case you can use the following:
var starttimestring = '2025-04-02 19:00:00';
var starttime = new GlideDateTime(starttimestring);
starttime.setTimeZone('Europe/London');
starttime.subtract(starttime.getTZOffset());
grChangeRequest.start_date = starttime;
In the second case remove the "setTimeZone" part.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 03:01 AM
Great !! @Scott Eaglesham
This function for DST will definitely be helpful.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 03:40 AM
Hello @Scott Eaglesham ,
Please note that this will only work as expected if you, or some other user who has "GMT" as their time zone, runs this script. If someone from for example Hongkong ran this script, isDST() would always return false because there is no DST in that time zone.
Internally, ServiceNow always uses UTC for date/time fields, and the string passed to GlideDateTime will always be interpreted as per UTC. So if you need a robust solution that always shows the date given in your string to a GMT user, no matter who ran the script, please check my original response.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 03:43 AM
I second that !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 06:11 AM
Thanks for the further info @Robert H. So if, for example, a Hong Kong based user ran the script using isDST(), which, as you say, always returns false for them, the field would be set incorrectly to UTC time instead of Hong Kong time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 06:17 AM
Also, would removing the "setTimeZone" part in your script work for all timezones, indluding GMT?