If you have the day of the year. How can you convert that to day of month and month? For example: The day "144" should be converted to 26th of May. I guess I also have to add the actual year to account for leap years. But I haven't found anything at all.
For example the function mktime() exepects the month, year and day of month.
Anybody some suggestions?
The most reliable and convenient way is to use the DateTime object. You can use DateTime::createFromFormat() static method to create it based on day in the current year:
$date = DateTime::createFromFormat('z', '144');
And because you know have DateTime object in the $date
variable, you can perform literally any task you want to. To output the contained date, simply call:
echo $date->format('j. n. Y');
It will print out 24. 5. 2012, because it's leap year and because it indexes days starting from zero (just like array indices).
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