Solved

get the last 8 mondays in a certain format

Posted on 2013-10-31
4
210 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

19 Experts available now in Live!

Get 1:1 Help Now