php check for a valid date, weird date conversions

后端 未结 10 773
盖世英雄少女心
盖世英雄少女心 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:24

    I have used the following code to validate dates coming from ExtJS applications.

    function check_sql_date_format($date) {
        $date = substr($date, 0, 10);
        list($year, $month, $day) = explode('-', $date);
        if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day)) {
            return false;
        }
        return checkdate($month, $day, $year);
    }
    

提交回复
热议问题