Hi all,
can anyone help with this ? I need to get the date of last Saturday from the current date.
Cheers in advance
read the manual... Keyword: mktime()
Yes, I did that before I came here - I am just looking for a quick answer as is everyone else. Answering each question with ' Look at the PHP.NET site' is OK but it doesnt really help. yes, I admit it I am lazy sometimes and I would rather try here first, before setting out for perhaps many hours of reading manuals.
:rolleyes:
Try this for size....
function getlastsaturday($year, $month, $day) { $dayno = date("w", mktime (0,0,0,$month,$day,$year)); $sat = date("Y-m-d", mktime(0,0,0,$month,($day - 1 - $dayno),$year)); return $sat; }
Yep, works like a treat.
cheers choppsta 🙂
Even easier:
$date=strtotime("last Saturday"); //gets timestamp for date $lastsat=date("M j Y", $date); //makes easy to read date from timestamp echo $lastsat; //nuff said
Just thought use http://www.php.net/manual/en/function.date.php for more date options
Sweeeeeeet...
See, the manual can give you the syntax and what have you, but it's people's different techniques and ideas that are interesting and help you find better and more efficient solutions...