search

Home  >  Q&A  >  body text

Define date boundaries in PHP

<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>
P粉546257913P粉546257913506 days ago493

reply all(1)I'll reply

  • P粉366946380

    P粉3669463802023-08-09 17:32:13

    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

    reply
    0
  • Cancelreply