The CreatorCon Call for Content is officially open! Get started here.

Get current month as a value

ZE
Kilo Contributor

How can I get the current month of the system date as a value, for example if current month is January then return 1, April return 4, etc...

 

I have a select box field variable on my catalog item called Month, with 12 choice questions create for user to pick from, these question choices are January - December with value 1 -12 correspondingly. I want to set the default value using javascript,

I had tried the following scripts in the default value field:

javascript: gs.getMonthLocalTime();

javascript:gs.nowDateTime(m);

javascript: var gdt = new GlideDateTime(); gs.info(gdt.getMonthLocalTime());

Please let me know what am I doing wrong

Thanks,

Ming.

1 ACCEPTED SOLUTION

Elijah Aromola
Mega Sage
javascript:new GlideDateTime().getMonth()

Try putting the following in the default value field. 

 

If this resolved your issue, please mark this as helpful!

View solution in original post

3 REPLIES 3

Prateek kumar
Mega Sage

Check this

getMonth()  is what you are looing for

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GDT-getMonth


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

Elijah Aromola
Mega Sage
javascript:new GlideDateTime().getMonth()

Try putting the following in the default value field. 

 

If this resolved your issue, please mark this as helpful!

Hi Elijah, 

how can we fetch "month" for a custom date field on value change? (10-12-2020) format.
This is client side


Regards
Priya