0

I need to know the first day-of-week in a given time period. The day of the week will change so it could be Sunday, Monday, Tuesday, Wednesday, Thursday, or Friday. For example: I need to find the first Monday between 2011-10-30 and 2011-12-11.

Scott
  • 3,290
  • 4
  • 29
  • 48

1 Answers1

1

Just a little math with the date('N') (day of the week) value:

$timestamp = strtotime('2011-11-08');
$weekday   = date('N', $timestamp);

if ($weekday > 1) {
    $timestamp = strtotime('+' . abs(8 - $weekday) . ' days', $timestamp);
}

echo date('D Y-m-d', $timestamp);
deceze
  • 510,633
  • 85
  • 743
  • 889