Neil Thompson
asked on
get the last 8 mondays in a certain format
Hi
I need to echo the last 8 mondays in the format day month year (eg 28 Oct 2013) BUT not include last Monday if the current day is not > wednesday
28 Oct 2013
21 Oct 2013
14 Oct 2013
07 Oct 2013
etc...
Require code please not links to php date pages as in a bit of a hurry on a project. full points for this by return.
Thanks
Neil
I need to echo the last 8 mondays in the format day month year (eg 28 Oct 2013) BUT not include last Monday if the current day is not > wednesday
28 Oct 2013
21 Oct 2013
14 Oct 2013
07 Oct 2013
etc...
Require code please not links to php date pages as in a bit of a hurry on a project. full points for this by return.
Thanks
Neil
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?php // RAY_temp_neilt.php
error_reporting(E_ALL);
// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28281914.html
// SEE http://php.net/manual/en/function.date.php
// I need to echo the last 8 mondays in the format day month year (eg 28 Oct 2013)
// BUT not include last Monday if the current day is not > wednesday
// SET THIS TO ANY STARTING DATE, INCLUDING 'TODAY' FOR TESTING
$anchor = 'Last Tuesday';
$anchor = 'Last Wednesday';
$anchor = 'Today';
// SET THIS TO THE PATTERN FOR THE DISPLAY
$pattern = 'j M Y';
// WHAT DAY OF THE WEEK IS IT?
$kounter = 1;
$weekday = date('w', strtotime($anchor));
if ($weekday <= 3) $kounter++;
// GET THE MONDAYS
$n = 8;
while ($n)
{
$mondays[] = date($pattern, strtotime("- $kounter Monday"));
$kounter++;
$n--;
}
// SHOW THE ARRAY OF MONDAYS
print_r($mondays);
HTH, ~Ray
Thanks for the points, ~Ray
ASKER