- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:12 AM
I have a weird issue between dev and prod instances. I have created a monthly scheduled job to run every three months:
var gdt = new GlideDate();
var mth = gdt.getMonth();
if (mth == 1 || mth == 4 || mth == 7 || mth == 10) { // Feb, May, Aug, Nov
answer = true
}
else {
answer = false;
}
In dev, this does not run despite the month being February (1). However, in prod, it runs just fine.
In dev, I changed the months in the condition to this:
if (mth == 0 || mth == 2 || mth == 6 || mth == 9)
It worked!
I then ran the following script as a background to confirm what mth was:
var gdt = new GlideDate();
var mth = gdt.getMonth();
gs.info(mth);
The output was: 2 (March?)
I then ran this:
var gdt = new Date();
var mth = gdt.getMonth();
gs.info(mth);
The output was 1 (February?)
This is the case in both instances.
So, why does the script work in prod and not in dev?
Why when I change the month in the condition does it work in dev?
What is the difference between Date and GlideDate?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:29 AM
Hi Wayne,
That is how it's defined, If you use the GlideRecord (OOB Service now GlideRecord API) for getMonth() then it provides the numeric value of Months starting from 1 to 12: GlideDateTime - Global
GlideDateTime - getMonth()
Gets the month stored by the GlideDateTime object, expressed in Java Virtual Machine time zone.
Returns
Type Description
Number The numerical value of the month, Jan=1, Dec=12.
But in general if you use the Javascript getMonth() function then it provides the numeric value of Months starting from 0 to 11.: JavaScript getMonth() Method
The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.
Please check the provided links for more details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 10:04 AM
That make sense to me, looks like there is an hr time difference between UK and Netherlands so when the job ran (with server time an hour behind) at that time it was still Jan for the getMonth() to recognize the month as Jan (1). Could be reason.
Other than that I don't see if OOB API or Javascript function is giving a wrong value.