Setting a Date-Time field with a GMT value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 03:50 AM
Hello all,
I'm trying to write a business rule that manipulates a date/time string always provided to us in GMT, to then populate a date-time field on a record.
I'm struggling to populate the field with the GMT time, ie it's always interpreted as the display time (local time).
Is there a function that directly sets a datetime field with the GMT time, so that the display time is then in the correct time zone?
I've tried using setValueUTC:
var dtNew = new GlideDateTime();
dtNew.setValueUTC("15-02-2011 08:00:00", "dd-MM-yyyy HH:mm:ss");
my_record.my_date_time = dtNew;
but in this case it's the display time of 'my_date_time' that ends up set to 15-02-2011 08:00:00.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 04:01 AM
Hi Jamie,
Please check section 3.6 for more info.
http://wiki.servicenow.com/index.php?title=GlideDateTime#setTZ.28tz.29
https://community.servicenow.com/thread/193835
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 05:14 AM
Thank you Pradeep. I am not sure how to make use of this...
If I have a GlideDateTime object, how do I set it to GMT using setTZ(tz), ie what do I need to pass in as tz?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 06:28 AM
I've done some more playing around, setting tz to some different values:
var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");
dtNew.setTZ(tz);
But
my_record.my_date_time = dtNew;
always sets the field with the same display value.
I feel I'm missing something fundamental!
Just to reiterate what I'm trying to do. I have a date-time, eg '2015-08-20 12:00:00'.
This date-time is GMT, and will be all year round. I want to set the value of a date-time field on a record to match this. We're GMT + 1 locally at the moment so when I set the field, it should display as 2015-08-20 13:00:00. Later in the year, when we're back on GMT locally, if I have date '2015-12-20 12:00:00' it should also display as '2015-12-20 12:00:00'.
Any help, appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 06:38 AM
Right, sussed it!
I just needed to use setValue(). That sets the GMT value of the GlideDateTime object.