Define date boundaries in PHP
P粉546257913
2023-08-08 19:34:46
<p>I used some date functions surrounding the French Republic of 1792-1806. But I want to know if the (PHP8) date functions can handle these dates. </p>
<pre class="brush:php;toolbar:false;">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;
}
}</pre>
<p>So a date like September 23, 1793 should be fine. But my function keeps returning false. </p>
If the date function returns false, you can get detailed error information by calling var_dump(date_get_last_errors()).
More information: https://www.php.net/manual/en/function.date-get-last-errors.php