php check for a valid date, weird date conversions

后端 未结 10 789
盖世英雄少女心
盖世英雄少女心 2020-12-10 04:13

Is there a way to check to see if a date/time is valid you would think these would be easy to check:

$date = \'0000-00-00\';
$time = \'00:00:00\';
$dateTime          


        
10条回答
  •  孤街浪徒
    2020-12-10 04:35

    As mentioned here: https://bugs.php.net/bug.php?id=45647

    There is no bug here, 00-00-00 means 2000-00-00, which is 1999-12-00, which is 1999-11-30. No bug, perfectly normal.

    And as shown with a few tests, rolling backwards is expected behavior, if a little unsettling:

    >> date('Y-m-d', strtotime('2012-03-00'))
    string: '2012-02-29'
    >> date('Y-m-d', strtotime('2012-02-00'))
    string: '2012-01-31'
    >> date('Y-m-d', strtotime('2012-01-00'))
    string: '2011-12-31'
    >> date('Y-m-d', strtotime('2012-00-00'))
    string: '2011-11-30'
    

提交回复
热议问题