Start and end date of a week in Servicenow

sgp
Kilo Contributor

Hi,

We have requirement to get start and end date of all  week in a month.

Could please help.

3 REPLIES 3

Ct111
Tera Sage
Hi, I didn't exactly what your requirement is but I think these links will be helpful to u https://community.servicenow.com/community?id=community_question&sys_id=a19b8b61db9cdbc01dcaf3231f961944 https://community.servicenow.com/community?id=community_question&sys_id=69c1df6ddbdcdbc01dcaf3231f961952 Mark my Answer as Correct n Helpful if it helped

Sunil B N
ServiceNow Employee
ServiceNow Employee

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.

Jeff Currier
ServiceNow Employee
ServiceNow Employee

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.