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

x
Solved

# List of dates of each friday

Posted on 2011-03-14
Medium Priority
426 Views
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);
}
``````
0
Question by:mikeydjr
• 2
• 2
• 2
• +1

LVL 8

Expert Comment

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);
}
``````
0

LVL 2

Expert Comment

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);
}

?>
``````
0

Author Comment

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

LVL 2

Expert Comment

ID: 35130614
can you give wanted result?
0

LVL 8

Expert Comment

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

Author Comment

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

Rik-Legger earned 2000 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);
}

?>
``````
0

## Featured Post

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …
###### Suggested Courses
Course of the Month6 days, 17 hours left to enroll