Why setDisplayValue in glide date time object adding 6 hrs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 03:42 AM
2024-11-13 06:00:00
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 04:23 AM - edited 11-05-2024 04:23 AM
I am not creating any script I want to know about existed script where they used setDisplayValue.
what makes difference between getValue and getDisplayValue ?
why its been showing as I shown above when i used getDisplayValue is the thing I didn't understand?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 04:30 AM
Basically getDisplayValue return in user's format and timezone. So thats the reason behind adding 6 hrs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 04:41 AM - edited 11-05-2024 04:44 AM
Its because your timezone is UTC-6 I would say.
When you use setDisplayValue() - depending on you own timezone - the actual value (setValue) changes to UTC+0
In my case because im in UTC+1 when i do the following my GDT will change the date to "yesterday at 23:00"
This is because I set the displayValue to midnight which actually tell ServiceNow to use 2024-22-04 23:00:00 as UTC date / time
var gdt = new GlideDateTime();
gdt.setDisplayValue('2024-11-05 00:00:00');
gs.info(gdt);
*** Script: 2024-11-04 23:00:00
When you set DisplayValue - you dont want to reteive gdt or .getValue() - because thats always converted either forward or backward depending on your own timezone.
Either SET DisplayValue AND get DisplayValue
Or SET Value AND get Value
Else you will confuse yourself
var gdt = new GlideDateTime();
gdt.setDisplayValue('2024-11-05 00:00:00');
gs.info(gdt.getDisplayValue());
Gives you
*** Script: 05/11/2024 00:00:00