i use several datefunction with dates around the French republic of 1792-1806.
But i want to know if the (php8) date function can handle these dates.
function CheckFrDate($CheckDate){
$BeginFrDate = date_create_from_format('d/m/Y', '22/09/1792');
$EndFrDate = date_create_from_format('d/m/Y', '22/09/1806');
if (
$CheckDate->getTimestamp() > $BeginFrDate->getTimestamp() &&
$CheckDate->getTimestamp() < $EndFrDate->getTimestamp()){
return 1;
}else{
return -1;
}
}
So a date like 23/09/1793 should be ok. But my function keeps returning false.
2
Answers
If a date function returns false, you are able to get the real (verbose) error message by calling
var_dump(date_get_last_errors());
read more:
https://www.php.net/manual/en/function.date-get-last-errors.php
I’d dare say that PHP date ranges do not have hard-coded limits, probably just the integer size or some similar platform limit. However, not all input mechanisms work the same way. For example:
In particular, date_create_from_format() reports this:
This happens because, as documented,
Y
format code is:Regarding your specific code, it appears to work as expected:
I no longer have a 32-bit Windows system to test but, if I recall correctly, DateTime interface was never affected by the 1970 Unix Epoch limit. However, if you use
->getTimestamp()
to obtain a Unix timestamp, you’ll get an integer that will be.You can drop Unix time altogether: