> > echo date("Y-m-d",strtotime("last Monday")), "\n";
> > yet gives me 2006-04-03 instead of 2006-03-27.
> Um, yes?  Today is Tuesday.  "Last Monday" was yesterday.  I guess it's
> a difference in interpretation ... PHP understands
> it to mean "the last day by that name which occurred."

Yeah, that's a bummer.   So...

echo date("Y-m-d",strtotime("last Monday -1 week")). "\n";

does the trick also as long as it's not currently Monday (the second
part of this problem).

The final solution is a simplified version of my earlier loop:

$day=date("l");
if ($day == "Monday")
{
$startdated=date('Y-m-d',strtotime('last Monday') );
}else{
$startdated=date('Y-m-d',strtotime('last Monday -1 week')) ;
}

Also, my calculations for $enddated (the end of the week period) were
corrupted by the fact that April has fewer days than March.  I
corrected this problem by calling "Sunday -1 week" (thanks Brian Bell)
instead of "last Sunday."

In retrospect, all of this probably would have made more sense in the
Triangle PHP mailing list.

MPF
--
TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
TriLUG Organizational FAQ  : http://trilug.org/faq/
TriLUG Member Services FAQ : http://members.trilug.org/services_faq/

Reply via email to