-1

嗨,我目前坚持使用 php 验证,我正在尝试针对 date() 进行日期测试;日期以确保日期是最新的,并且不允许任何小于当前日期的日期()

 public function checkDateField($month, $day, $year)
       {
            if (!is_numeric($month) || !is_numeric($day) || !is_numeric($year) || !checkdate($month, $day, $year)) {
                $msg = '*Invalid date';


// then some where here test the value 
of $month $day $year >= date... 
something like that?
///           
            }
            return $msg;    
       }
4

3 回答 3

0

也许使用 datetime diff 函数将您的日期与 now() 进行比较:http ://www.php.net/manual/en/datetime.diff.php

希望这可以帮助 !

于 2013-04-22T14:40:36.500 回答
0
public function checkDateField($month, $day, $year){

    if (!is_numeric($month) || !is_numeric($day) || !is_numeric($year) return 'Invalid date';

    if (strtotime($year.'-'.$month.'-'.$day.' 23:59:59') < time()){
        return 'Invalid time';
    }

}
于 2013-04-22T14:44:50.850 回答
0

像这样的东西应该可以工作(假设日期格式 YYYY-MM-DD):

function isValidFutureDate($date)
{
    if (false === strtotime($date))
    {
        return false;
    }

    list($year, $month, $day) = explode('-', $date);
    if (false === checkdate($month, $day, $year))
    {
        return false
    }

    $now = new DateTime();
    $compare = new DateTime($date);
    if ($compare < $now)
    {
        return false;
    }
}
于 2013-04-22T14:41:59.147 回答