Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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
0
Neil Thompson
Asked:
Neil Thompson
  • 3
1 Solution
 
Ray PaseurCommented:
The answers are in here somewhere, just scan for the practical examples.  I'll try to give you a specific answer in a moment.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Thanks Ray, as always your tutorials are very easy to follow and I managed to get what I needed instantly. Neil
0
 
Ray PaseurCommented:
<?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
0
 
Ray PaseurCommented:
Thanks for the points, ~Ray
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now