Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Vishal Birajdar
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

Sohail Khilji
Kilo Patron

Try to use .getDayOfWeekLocalTime(); 

 

It must work !


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Ranjit Nimbalka
Mega Sage

Hi @Dominik1988 ,

 

Please check your instance time zone and then try script is correct.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit

 

 

 

 

Vishal Birajdar
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

Harish Bainsla
Kilo Patron
Kilo Patron

Hi you can use below code i try in background script its work

var today = new Date();
var dayOfWeek = today.getDay();
gs.print(dayOfWeek);
HarishBainsla_0-1709625980485.png