I want the code below to add 1 day, but the added day must be a weekday, not a weekend

chandusnow2
Tera Contributor

var date = fd_data.trigger.current.u_cc_cm_ass_date;
var gdt = new GlideDateTime(date);                  
gdt.addDaysUTC(1);                                  
return gdt.getDate().getValue();                  
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@chandusnow2 

try this

var date = fd_data.trigger.current.u_cc_cm_ass_date;
var gdt = new GlideDateTime(date + ' 00:00:00');
gdt.addDaysUTC(1);

// if saturday add 2 days to get monday
if (gdt.getDayOfWeekUTC() == 6) {
    gdt.addDaysLocalTime(2);
} else if (gdt.getDayOfWeekUTC() == 7) {
    gdt.addDaysLocalTime(1); // if sunday then add 1 day to get monday
}

return gdt.getDate();

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@chandusnow2 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

sarah_bioni
ServiceNow Employee

Hi @chandusnow2 ,

 

Did you try this?

var startDate = new GlideDateTime('2026-01-30 14:00:00');
var days = 1;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae');
var end = schedule.add(startDate, dur);
gs.info(end.getDate().getValue());

Ankur Bawiskar
Tera Patron

@chandusnow2 

try this

var date = fd_data.trigger.current.u_cc_cm_ass_date;
var gdt = new GlideDateTime(date + ' 00:00:00');
gdt.addDaysUTC(1);

// if saturday add 2 days to get monday
if (gdt.getDayOfWeekUTC() == 6) {
    gdt.addDaysLocalTime(2);
} else if (gdt.getDayOfWeekUTC() == 7) {
    gdt.addDaysLocalTime(1); // if sunday then add 1 day to get monday
}

return gdt.getDate();

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@chandusnow2 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

chandusnow2
Tera Contributor

@Ankur Bawiskar  Tq for responce it is working fine as per requirement