tags:

views:

49

answers:

2
$day = date('l', strtotime('07/25/2010'));
echo "$day ";
echo date("m/d/Y", strtotime("first $day"));

This prints out Sunday 07/11/2010

$day = date('l', strtotime('07/25/2010'));
echo "$day ";
echo date("m/d/Y", strtotime("last $day"));

This prints out Sunday 07/04/2010

What's going on here? Shouldn't it be 07/04/2010 and 07/25/2010 respectively?

A: 

I can say something to last, read Datetime - Relative Formats:

"'last' dayname" takes the last dayname from the current day. (Example: "last wed july 2008" means "2008-06-25"; "july 2008" first sets the current date to "2008-07-01" and then "last wed" moves to the previous Wednesday which is "2008-06-25").

I guess it is similar with first it gives you the next dayname.

Felix Kling
+1  A: 

I think the answers are correct, because they are relative to the given date (which when not given defaults to today).

Based on the PHP docs:

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

So FIRST SUNDAY is in fact the 11th, and LAST SUNDAY was in fact the 4th. Based on the wording of your question, it appears you are looking for the 1st Sunday of the month, and the last Sunday of the month. This function returns the first Sunday AFTER today, and the LAST Sunday before today.

MJB
I believe you are correct, when I change the date 07/01/2010 I get what I'm looking for.
kylex