Weird issue with Dates: getmonth returns previous month on the 1st

echalum
Kilo Contributor

In one of my forms/workflows, the user picks a date which is put in the short description as Month/Year. The problem: When the user picks 10/1/2019, the short description puts 9/2019 but when the user picks a different date like 10/15/2019 or 10/2/2019 the short description puts 10/2019. 

 

var event = new GlideDateTime(current.variable_pool.usabyod_date); 

current.short_description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonth() +"/"+ event.getYear();
1 ACCEPTED SOLUTION

Hi,

can you try with getMonthUTC()

var event = new GlideDateTime(current.variable_pool.usabyod_date); 

current.short_description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonthUTC() +"/"+ event.getYear();
current.description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonthUTC() +"/"+event.getYear();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Prateek kumar
Mega Sage

Can you try 

getMonthLocalTime()

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

echalum
Kilo Contributor

Still getting a 9 instead of the 10. 

var event = new GlideDateTime(current.variable_pool.usabyod_date); 

current.short_description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonthLocalTime() +"/"+ event.getYear();
current.description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonthLocalTime() +"/"+event.getYear();

See if changing it to getMonthUTC() will help

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi,

can you try with getMonthUTC()

var event = new GlideDateTime(current.variable_pool.usabyod_date); 

current.short_description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonthUTC() +"/"+ event.getYear();
current.description="Receipt for " + current.variable_pool.usabyod_name.name +" "+ event.getMonthUTC() +"/"+event.getYear();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader