Solved

get the last 8 mondays in a certain format

Posted on 2013-10-31
4
207 Views
Last Modified: 2013-10-31
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
Comment
Question by:NeilT
  • 3
4 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39613974
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
 
LVL 3

Author Closing Comment

by:NeilT
ID: 39614021
Thanks Ray, as always your tutorials are very easy to follow and I managed to get what I needed instantly. Neil
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39614033
<?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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39614034
Thanks for the points, ~Ray
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now