How could I get the date of next monday(any other day) in script include?

appsicumdisplay
Mega Contributor

Hello All,

     

        I have a search about this question on community's threads but not got my answer. So could you please help to get the date of next monday(or any other day) if a date is provided.

Suppose I have a date 2015-12-10 and I have a day in Integer(1),

as per SNow: 1 for Monday and 7 for Sunday.

Now a function return me the date(2015-12-14).

Or if i have date 2015-12-14 then return me 2015-12-14.

Thanks-

Macarius Anna

4 REPLIES 4

Deepak Ingale1
Mega Sage

var todayDateTime = new GlideDateTime(nowDateTime());


var integerValForToday = todayDateTime.getDayOfWeekLocalTime();


gs.print(integerValForToday);


var adderForMonday = 15- integerValForToday; // Change 15 to 8 if you want to find the coming week monday, 15 will return next week monday


todayDateTime.addDaysLocalTime(adderForMonday);


gs.print(todayDateTime.getLocalDate()); // Store the value inside the gs.print to any varaible. I have run this script as background to check if returns correct value. It worked for me


Hi Anna,



I have run the above code a scripts background and it worked for me.


You can convert it to script include as per your requirement.



For reference to GlideDate APIs check below link


ServiceNow Developers



For reference to GlideDateTime APIs check below link


ServiceNow Developers


Thanks Deepak,


        You give me a direction to get next day from a date. This is really very helpful.


This helped today!


It Really helps me alot.

Thanks