How to convert float to date time in php?
In this tutorial, we show you how you can convert float to date time in php.
1. Code:
<?php
function convertFloatToDateTime($timeFloat, $isDateTime = false){
if (is_null($timeFloat) || trim($timeFloat) == '') {
return null;
}
if ($isDateTime) {
$str = date("d-m-Y H:i:s", strtotime("+0 second", $timeFloat));
} else {
$str = date("d-m-Y", strtotime("+0 second", $timeFloat));
}
return (false != $str) ? $str : null;
}
$str = convertFloatToDateTime(11111111111, false);
echo($str);
echo("<br>");
$str = convertFloatToDateTime(11111111111, true);
echo($str);
?>
2. Example:
Input:
11111111111, false; 11111111111, true;
Output:
05-02-2322 05-02-2322 20:45:11