Solved

List of dates of each friday

Posted on 2011-03-14
7
396 Views
Last Modified: 2013-12-13
Found this code on the web, gives me a list of the dates of each friday. However I need the sort reversed. Current friday at top then descending order of each friday
$start = strtotime("today"); // your start/end dates here
$end = strtotime("today + 1 years");

$friday = strtotime("friday", $start);
while($friday <= $end) {
    echo "fri=", date("m-d-y", $friday), "\n";
   echo "<br>";
    $friday = strtotime("+1 weeks", $friday);
}

Open in new window

0
Comment
Question by:mikeydjr
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 8

Expert Comment

by:jsvor
ID: 35130011
Here you go.
 
$start = strtotime("today"); // your start/end dates here
$end = strtotime("today + 1 years");

$friday = strtotime("friday", $end);
while($friday >= $start) {
    echo "fri=", date("m-d-y", $friday), "\n";
   echo "<br>";
    $friday = strtotime("-1 weeks", $friday);
}

Open in new window

0
 
LVL 2

Expert Comment

by:sihar86
ID: 35130083
<?

$start = strtotime("today"); // your start/end dates here
$end = strtotime("today + 1 years");

$currentfriday = strtotime("friday", $start);
echo "fri=", date("m-d-y", $currentfriday), "<br>"; //print the current friday
$endfriday = strtotime("friday", $end); //set to next friday

while($endfriday > $currentfriday) {  //print in descending order
    echo "fri=", date("m-d-y", $endfriday), "<br>";
    $endfriday = strtotime("-1 weeks", $endfriday);   
}

?>

Open in new window

0
 

Author Comment

by:mikeydjr
ID: 35130482
Sorry, don't think I was clear. What I need is a list of Fridays starting from the current Friday going back each week and listing Fridays in descending order.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:sihar86
ID: 35130614
can you give wanted result?
0
 
LVL 8

Expert Comment

by:jsvor
ID: 35130656
Isn't that was the original code does?  I guess we need an example of what you want.
0
 

Author Comment

by:mikeydjr
ID: 35131206
Something like:

3-18-11
3-11-11
3-04-11
2-25-11
2-18-11
2-11-11
2-04-11
etc
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35133771
The + signs becomes - (minus) and you have to flip the 'smaller than' sign to an 'bigger then' sign.

<?php
$start = strtotime("today"); // your start/end dates here
$end = strtotime("today - 1 years");

$friday = strtotime("friday", $start);
while($friday >= $end) {
    echo "fri=", date("m-d-y", $friday), "\n";
   echo "<br>";
    $friday = strtotime("-1 weeks", $friday);
}
    
?> 

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

763 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