Looping through all the days in the current month with PHP.
This loop will start at the first day of the current month with each loop adding 1 day, the loop will continue until the current month is no longer less than or equal to the last looped day/date.
<?php $date = date('F Y');//Current Month Year while (strtotime($date) <= strtotime(date('Y-m') . '-' . date('t', strtotime($date)))) { $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));//Adds 1 day onto current date }
Now to add in some formatted DateTime values:
$day_num = date('j', strtotime($date));//Day number $day_name = date('l', strtotime($date));//Day name $day_abrev = date('S', strtotime($date));//th, nd, st and rd $day = "$day_name $day_num$day_abrev";
The full script:
<?php $date = date('F Y');//Current Month Year while (strtotime($date) <= strtotime(date('Y-m') . '-' . date('t', strtotime($date)))) { $day_num = date('j', strtotime($date));//Day number $day_name = date('l', strtotime($date));//Day name $day_abrev = date('S', strtotime($date));//th, nd, st and rd $day = "$day_name $day_num $day_abrev"; $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));//Adds 1 day onto current date echo $day . '<br>'; }
This will output (As for October 2020):
Thursday 1st Friday 2nd Saturday 3rd Sunday 4th Monday 5th Tuesday 6th Wednesday 7th Thursday 8th ...
You can change the date formating with values from here.