The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Date and GlideDate confusion

Wayne Richmond
Giga Guru

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?

1 ACCEPTED SOLUTION

Shishir Srivast
Mega Sage

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.


View solution in original post

10 REPLIES 10

Chandu Telu
Tera Guru
Tera Guru

Hi Rich,



GlideDate is server date provide by service-now



new Date() is javascript date


new Date()



find_real_file.png



GlideDate is server date provide by service-now



find_real_file.png



Date format difference


I think date and time format difference is dev and prod instance can you check.


They are both dd-MM-yy