Start and end date of a week in Servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-24-2018 08:04 AM
Hi,
We have requirement to get start and end date of all week in a month.
Could please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-24-2018 08:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-24-2018 08:16 AM
Hi,
I am not sure about the use case, but you can make use of Schedules within ServiceNow to generate and get the start date and end date of there schedule entries. And then you can use GlideSchedule APIs to get start and end date of all weeks.
Cheers,
Sunil B N
P.S: Please mark this as an answer/helpful if it was useful for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-24-2018 08:17 AM
You could use these two:
getBeginningOfWeek: function(date) {
var gdt = new GlideDateTime(date);
gdt.addDays(-1 * gdt.getDayOfWeekUTC() + 1);
return gdt;
},
getEndOfWeek: function(date) {
var gdt = new GlideDateTime(date);
gdt.addDays(7 - gdt.getDayOfWeekUTC());
var gTime = new GlideTime();
gTime.setValue("23:59:59");
gdt.add(gTime);
return gdt;
},
If you entered entered the first day of the specific month for the first two calls, you would get the first week. Then use the 7, 14, 21, and 28th for the others. You need to decide how you treat the first and last weeks of a month when they cross months.