Get the most recently occurring Sunday

To safely add exactly one day, use:

d.setDate(d.getDate() + 1);

which is daylight saving safe. To set a date object to the last Sunday:

function setToLastSunday(d) {
  return d.setDate(d.getDate() - d.getDay());
}

Or to return a new Date object for last Sunday:

function getLastSunday(d) {
  var t = new Date(d);
  t.setDate(t.getDate() - t.getDay());
  return t;
}

Edit

The original answer had an incorrect version adding time, that does add one day but not how the OP wants.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)