0
votes

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.

1
please point out why none of stackoverflow.com/search?q=first+day+of+week+php helped solve your questionGordon
I'm not always looking for the first day of the week.Scott

1 Answers

1
votes

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);