[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

List of dates of each friday

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
mikeydjr
Asked:
mikeydjr
  • 2
  • 2
  • 2
  • +1
1 Solution
 
jsvorCommented:
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
 
sihar86Commented:
<?

$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
 
mikeydjrAuthor Commented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
sihar86Commented:
can you give wanted result?
0
 
jsvorCommented:
Isn't that was the original code does?  I guess we need an example of what you want.
0
 
mikeydjrAuthor Commented:
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
 
Rik-LeggerCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now