Get week from date through script in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 06:32 AM - edited 02-05-2024 06:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 08:52 PM
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:
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.