Solved

get the last 8 mondays in a certain format

Posted on 2013-10-31
4
223 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:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 110

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:Neil Thompson
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 110

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 110

Expert Comment

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

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

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.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

635 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