I need to convert a number to a date ie
1 -> Sunday
2 -> Monday
I have the following question which aids with the opposite: day of the week to day number (Monday = 1, Tuesday = 2)
Once I am able to do this I could for example loop through and echo the day ie:
while($i < 7)
{
echo date("N",strtotime(1));
}
Everything I am searching for seems to be people asking to convert a day to a number. Can someone please point me in the right direction
Just put the days in an array using the day of the week as the key. Then use date('N')
to get the day of the week and use that as they key to access that array value.
$days = [
1 => 'Sunday',
2 => 'Monday',
3 => 'Tuesday',
4 => 'Wednesday',
5 => 'Thursday',
6 => 'Friday',
7 => 'Saturday'
];
echo $days[date('N')];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With