I have value
$days = 166.0444;
which is day of the year. How can I simply convert this value to its datetime, which should be
If its the current year, you can
$days = 166.0444;
$date = new DateTime();
$date->setDate($date->format('Y'), 1, 1);
$date->add(new DateInterval('P' . floor($days) . 'D'));
You can do it in this or similar way:
function convertDaysToDateTime($days, $year){
$datetime = new DateTime();
return $datetime->setTimestamp(mktime(0,0,0,0,0,$year) + $days * 24 * 3600);
}
$days = 166.0444;
$datetime = convertDaysToDateTime($days, date('Y'));
echo $datetime->format('U = Y-m-d H:i:s');