Last 12 Fridays

Hi everyone!

I have been looking around with no luck for exactly why I am looking for, that is, a way to get into an array the last 12 past fridays with current date as a begining. mm/dd/yyyy format.

Thank you very much to anyone who can give me an example.

[php]$d = new DateTime();
for ($i = 1; $i < 13; $i ++) {
while ($d->format(‘l’) != ‘Friday’) {
$d->modify(’-1 day’);
}
echo “

{$i}: {$d->format(‘l m/d/Y’)}

”;
$d->modify(’-1 week’);
}
[/php]

Awesome!!!

One thing though, is there a way to begin the date to start displaying from the last Friday to the most current friday?

Example:

1: Friday 01/15/2016
2: Friday 01/22/2016
3: Friday 01/29/2016
4: Friday 02/05/2016
5: Friday 02/12/2016
6: Friday 02/19/2016
7: Friday 02/26/2016
8: Friday 03/04/2016
9: Friday 03/11/2016
10: Friday 03/18/2016
11: Friday 03/25/2016
12: Friday 04/01/2016

Again, thank you for taking the time to help

Add them to an array and sort them how you want to.

I was playing around with your code and found the solution :slight_smile: Thanks !!!

Just modified a few things:

$d = new DateTime(); 
$d->modify('-12 week');

for ($i = 1; $i < 13; $i ++) {
while ($d->format(‘l’) != ‘Friday’) {
$d->modify(’+1 day’);
}
echo “

{$i}: {$d->format(‘l m/d/Y’)}

”;
$d->modify(’+1 week’);
}
Sponsor our Newsletter | Privacy Policy | Terms of Service