- 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 09:25 AM
Thanks. So why is the month different?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:30 AM
Here is the tricky point
date format different in dev and prod this is the reason why you getting the month different
EX:
in dev date is 12/2/2018(DD/MM/yyyy)
in test date 1/12/2018(MM/DD/YYYY)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:57 AM
Thanks but the date formats are the same in both instances

- 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 09:56 AM
Thanks, this is a very detailed explanation but I still don't understand by the following scheduled job ran successfully in prod today given I used GlideDateTime (which shouldn't have recognise 1 as the current month):
// Run every 3 months (when month is Jan (1), Apr (4), Jul (7) or Oct (10))
var gdt = new GlideDateTime();
var mth = gdt.getMonth();
if (mth == 1 || mth == 4 || mth == 7 || mth == 10) {
answer = true
}
else {
answer = false;
}
The time the job ran is 00:08:00. Could that make a difference (if server time was an hour behind maybe, therefore the previous day (and month))? I'm in the UK and our servers are located Amsterdam and Dublin.