- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:16 PM
Hi guys,
I have the following problem:
I´m using the method getGlideObject() to get the value of a glide date/time field in order to check if that time falls within a schedule I have created.
When using the method, It adds 5 hours to actual value of the field?
Why is this?
Is it because it is taking the time from the object with some default time zone and that´s why it adds 5 hours?
Is there a way to check the time zone in which the date is being stored?
Seems possible, but I can´t find anything related. Please help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:44 PM
try below
var schedRec = new GlideRecord('cmn_schedule');
var name = schedRec.get('name', '8-5 weekdays');
var sched = new GlideSchedule(schedRec.sys_id);
var currentDateTime = new GlideDateTime();
currentDateTime.setValue(current.u_tsf_fecha_workshop);
gs.addErrorMessage('currentDateTime after: ' + currentDateTime.getDisplayValue());
if (sched.isInSchedule(currentDateTime)) {
var dur = new GlideDuration(60 * 60 * 16 * 1000);
var newDateTime = sched.add(currentDateTime, durToAdd, '');
// var currentWSDate = current.u_tsf_fecha_wsreal.getGlideObject();
gs.addErrorMessage('current.u_tsf_fecha_wsreal: ' + newDateTime.getDisplayValue());
} else {
current.setValue("u_tsf_fecha_workshop", "");
gs.setRedirect(current);
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:44 PM
try below
var schedRec = new GlideRecord('cmn_schedule');
var name = schedRec.get('name', '8-5 weekdays');
var sched = new GlideSchedule(schedRec.sys_id);
var currentDateTime = new GlideDateTime();
currentDateTime.setValue(current.u_tsf_fecha_workshop);
gs.addErrorMessage('currentDateTime after: ' + currentDateTime.getDisplayValue());
if (sched.isInSchedule(currentDateTime)) {
var dur = new GlideDuration(60 * 60 * 16 * 1000);
var newDateTime = sched.add(currentDateTime, durToAdd, '');
// var currentWSDate = current.u_tsf_fecha_wsreal.getGlideObject();
gs.addErrorMessage('current.u_tsf_fecha_wsreal: ' + newDateTime.getDisplayValue());
} else {
current.setValue("u_tsf_fecha_workshop", "");
gs.setRedirect(current);
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 01:01 PM
Thank you so much Mike. I have marked the answer as correcy.
So a workaround was to use a glide date time object to get the exact value of the field, it gets the display value and no timezone attribute involved.
I tried using the getDisplayValue method rather than the getGlideObject, but the format was not compatible when it checked if that time fell inside the schedule defined.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:21 PM
Hi ,
Here is a link which will help you.
If it helps,Please mark ✅ Correct and 👍 Helpful.
Warm Regards,
Milind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:23 PM
Hi Milind,
Yeah, I´ve used that article which I found very useful, but the issue is the value that is inside the object that is being read out loud is in another time zone...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:50 PM
Hi,
By default new GlideDateTime() returns the time in GMT.
you can fetch the date/time in your timezone using this
var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");
var gdt = new GlideDateTime();
gdt.setTZ(tz);
gdt.setValue(your_value);
gs.print(gdt.getDisplayValue());