We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

getDay()

Dominik1988
Tera Expert

Hello!

Irun simple function on background script.

 

var today = new Date();
dayOfWeek = today.getDay();
gs.print(dayOfWeek);
 
Today is Thuesday so I suposed to get result like "2" . but I receive "1" , did I make a mistake somewhere? why is that?
Thanks for any reply.
1 ACCEPTED SOLUTION

VishalB06557037
Giga Sage

Hello @Dominik1988 

 

Try like below :

 

var t = new Date();
gs.print(t.getUTCDay())

 

 

VishalBirajdar_0-1709625684733.png

 

Note : Use GlideDateTime API instead Date

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

5 REPLIES 5

Dominik1988
Tera Expert

Don't know what happen but sudenly it started work for me even with my code, perhaps something was not refreshed on instance or on my browser?  I hope this will work tommorow 🙂