Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Get week from date through script in servicenow

Neeraja2
Tera Contributor

Hello Everyone,

I need to get week from a date in a month. Not in a year.

For example, 

for example : if date is 2024-02-05

The output should be :

week - 1st week (as it is 1st week of February and not year)

 

Please anyone suggest script on this? Thanks in advance

10 REPLIES 10

Rohit_Burud
Tera Contributor

Hi @Neeraja2 ,
I tried below code:

var prefixes = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
var gdt = new GlideDateTime("02-22-2024");
var day=gdt.getDayOfMonthLocalTime();
var month=gdt.getMonthLocalTime();
gs.log('This is '+prefixes[0 | day / 7]+' Week of Month'+' '+month);

Output:

Rohit_Burud_0-1714708341239.png


Regards,
Rohit B

Kindly mark my response as helpful and correct if it assisted you.
Please mark my response as Correct/Helpful based on Impact.