- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 07:20 AM
Hi Experts,
Can you please help understand the difference between
GlideDate, GlideDateTime
Vs
Packages.com.glide.glideobject.GlideDate, Packages.com.glide.glideobject.GlideDateTime
Also, why do we get a different date when we include the time component to the GlideDate.
Here is the code I am trying to execute in BGScript
var nowDay = new Packages.com.glide.glideobject.GlideDate();
nowDay.setDisplayValue(gs.now());
var nowDayUNIX = nowDay.getNumericValue();
gs.print(nowDay+" "+nowDayUNIX);
var nowDay = new Packages.com.glide.glideobject.GlideDateTime();
nowDay.setDisplayValue(gs.now());
var nowDayUNIX = nowDay.getNumericValue();
gs.print(nowDay+" "+nowDayUNIX);
var gd= new GlideDate();
gd.setDisplayValue(gs.now());
var ngd = gd.getNumericValue();
gs.print(gd+" "+ngd);
var gd= new GlideDateTime();
gd.setDisplayValue(gs.now());
var ngd = gd.getNumericValue();
gs.print(gd+" "+ngd);
Output:
*** Script: 2019-12-06 1575590400000
*** Script: 2019-12-05 13:00:00 1575550800000
*** Script: 2019-12-06 1575590400000
*** Script: 2019-12-05 13:00:00 1575550800000
May be a silly one, but thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2019 06:18 AM
The function gs.now() returns a string which is the current date in your local time zone.
If you execute this code
var gd = new GlideDateTime();
gd.setDisplayValue(gs.now());
Then you are setting gd to midnight local time for the current date.
If you print gd.getDisplayValue(), then it will print midnight local time for the current date.
However, if you print gd.getValue() or simply gd, then it will print that time in UTC.
If you are in the eastern hemisphere, then the current UTC date could be yesterday, which is apparently what is happening in your case.
Please mark reply helpful and/or correct if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 04:24 PM
Packages.com.glide.glideobject.GlideDateTime is the old name for GlideDateTime.
It is recommended that you use the new syntax, which is GlideDateTime or GlideDate.
GlideDate is the GlideDateTime with the time removed. When you call getNumericValue() for a GlideDate you are getting the epoch time as of midnight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2019 03:53 AM
Thank you Giles.
Please correct me if I am wrong, if GlideDateTime is just including the time component to the date, why am I getting a different date altogether( which is the previous day). Please see below,
*** Script: 2019-12-06 (GlideDate output)
*** Script: 2019-12-05 13:00:00 (GlideDateTime output)
Should it not be something like below, i.e the date is same, but GlideDateTime will display the time additionally?
*** Script: 2019-12-06 (GlideDate output)
*** Script: 2019-12-06 13:00:00 (GlideDateTime output)
Am I missing something here

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2019 06:18 AM
The function gs.now() returns a string which is the current date in your local time zone.
If you execute this code
var gd = new GlideDateTime();
gd.setDisplayValue(gs.now());
Then you are setting gd to midnight local time for the current date.
If you print gd.getDisplayValue(), then it will print midnight local time for the current date.
However, if you print gd.getValue() or simply gd, then it will print that time in UTC.
If you are in the eastern hemisphere, then the current UTC date could be yesterday, which is apparently what is happening in your case.
Please mark reply helpful and/or correct if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 02:31 AM
Got it. Thank you Giles!