I want a date after ‘n’ days from a given date in ‘yyyymmdd’ format (output is also in same format).Adding n days should exclude Sundays. Is it possible to do this in javascript?
Here is my code to add n days to a date
function mydate(dateStr,offset)
{
var ymd = dateStr.match(/^(\d{4})(\d{2})(\d{2})$/);
if (ymd)
{
var date = new Date(ymd[1], ymd[2] - 1, ymd[3]);
date.setDate(date.getDate() + offset);
return $.datepicker.formatDate('yymmdd', date);
}
else
{ // parse error
return null;
}
}
for example,
mydate('19890831',10)
will return
19890910
but actually what I need is ‘19891012’ because there are 2 Sundays when we add 10 days to the ‘19890831’
Simple solution; you can just loop through the days and skip sundays: