PDA

Click to See Complete Forum and Search --> : [PHP] What was the date on monday?


andrewb
Oct 25th, 2006, 03:03 AM
I got annoyed finding something simple to find the date for monday in the current week (easily adapted for to find the monday for any given date) - so I gave up being lazy, and whipped up my own quick and dirty example. Please be gentle - I'm a noob obviously lol.

Putting it here also keeps it stored for my future use too :p


// Get the numerical representation for the current weekday where 1=monday, 7=sunday.
// We subtract 1 to avoid an over-subtraction in the next line.
$tod=date("N")-1;
// Gets the timestamp for monday by counting how many days we are currently
// away from monday (less 1, as above)
$mon=strtotime('-'.$tod.' days');
// Just for demo purposes, the formatted date
echo date('d M Y',$mon);