View Full Version : getting dates for previous days within a 7 day period

sir pannels
01-04-2008, 06:04 PM
Hello all,

Have a task that I can't quite get my head around how to put it into code.

I need to work out the date of any day of the week from the last 7 period. So for example today it is Friday the 4th of Jan 2008, I need to know what the date was on the last monday within 7 days (31st dec 2007) or another one... i need to know what the date was last Tuesday (2nd jan 2008) and so forth.

Any one have any resources on this sort of thing?

many thanks all help appreciated :)
Warm Regards,
Sir P :D

01-04-2008, 06:20 PM
Check out the strtotime() (http://ca3.php.net/manual/en/function.strtotime.php) function, could be just what your looking for. For your example, you would literally type in:

$lastMon = strtotime('last Monday');

Returns a timestamp, so you will need to format it using the data function. Hope that helps you!