- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 09:40 PM
I need to get the week number that 1st week or 2nd week, and the month name and the year . The month name and year i can do it using javascript but i am not able to understannd how to get the week number . Suppose if I run the code now as it is 2nd week of May it must display like This is 2nd Week of Month May : 2017
I got the month name and year by this code
var monthNames = ',January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
var gdt = new GlideDateTime();
var month=(monthNames[new GlideDate().getMonthLocalTime()]+":"+gdt.getYear());
I am not able to get the week number.Need help..
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 10:18 PM
hi Suprakash,
here you go.
var monthNames = ',January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
var prefixes = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
var gdt = new GlideDateTime();
var month=(monthNames[gdt.getMonthLocalTime()]+":"+gdt.getYear());
var day=gdt.getDayOfMonthLocalTime();
gs.log('This is '+prefixes[0 | day / 7]+' Week of Month '+month);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 09:48 PM
Hellow Suprakash,
Refer the below link may helpful to you.
http://wiki.servicenow.com/index.php?title=GlideDateTime#gsc.tab=0
http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#gsc.tab=0
ServiceNow Commnunity MVP -2018 class.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 10:18 PM
hi Suprakash,
here you go.
var monthNames = ',January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
var prefixes = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
var gdt = new GlideDateTime();
var month=(monthNames[gdt.getMonthLocalTime()]+":"+gdt.getYear());
var day=gdt.getDayOfMonthLocalTime();
gs.log('This is '+prefixes[0 | day / 7]+' Week of Month '+month);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2020 12:46 PM
Where do I need to apply this? I would also like to display the week numbers in my reports.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2023 12:16 AM
@Bryan Tay3 This code doesn't work for month of February, Can you please help. if I take a date as 2023-02-27, it shows week 4th, but it is 5th week