I'm trying to use a DateTime
object to calculate the current date from the number of days since Jan 1st. Leap years are very important here. Apparently, this does not account for leap years, however.
Here's my code:
$date = DateTime::createFromFormat('z Y', '59 2016');
echo $date->format('n/j/Y')."\n";
die();
Turns out this is a reported PHP bug from 2012 that I JUST found while I was making this question:
https://bugs.php.net/bug.php?id=62476
That's annoying.
Here is a workaround:
$date = DateTime::createFromFormat('m/d/Y', '01/01/2016');
$date->add(date_interval_create_from_date_string('59 days'));
echo $date->format('m/d/Y')."\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