Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

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
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Neil Thompson

ASKER

Thanks Ray, as always your tutorials are very easy to follow and I managed to get what I needed instantly. Neil
<?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);

Open in new window

HTH, ~Ray
Thanks for the points, ~Ray