I have a timestamp in a variable
$data = (float) -2208988800;
Is it possible to create correct date from this data?
date("d.M.Y", $data) returns "07.02.2036"
You get result 07.02.2036 because you are on x86 (32-bit machine), where integer range is from -2147483648 to 2147483647 (see echo PHP_INT_MAX;). PHP internally cast's 2nd parameter of date() function to integer, so on 32-bit machine, string or float -2208988800 will become integer 2085978496, which is date 2036-02-07, demo.
echo date('Y-m-d', -2208988800);
# 2036-02-07 (x86)
# 1900-01-01 (x64)
run code on x86 machine
run code on x64 machine
If you wish to use negative timestamps on both machines, x86 and x64, use DateTime extension:
$dt = new DateTime('@-2208988800');
echo $dt->format('Y-m-d');
demo
Note that, for dates before the unix epoch, method getTimestamp() will return false, where method format('U') will return a correct timestamp number.
var_dump( $dt->format('U') ); # -2208988800
var_dump( $dt->getTimestamp() ); # false
demo
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