2013-04-22 47 views
-1

嗨即时通讯与PHP验证,即时通讯尝试使日期测试对 日期();日期,以确保日期是最新的,不会允许任何日期,现在多数民众赞成小于当前日期()PHP验证与现在()日期和插入时间

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;  
     } 
+3

我很遗憾听到这个消息。你有什么问题? – 2013-04-22 14:38:23

+0

'checkdate($ month,$ day,$ year)> time()' – x4rf41 2013-04-22 14:39:57

+0

我必须对当前的Now()日期测试$ month $ day $ year,并确保它更大或发送invaliddate – 2013-04-22 14:40:33

回答

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; 
    } 
} 
+0

对不起,我刚刚更新 – 2013-04-22 14:58:58

+0

我不知道这不是你要找的。谨慎解释? – 2013-04-22 15:06:44

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'; 
    } 

} 
+0

对不起,我只是更新我的意思是日期没有时间抱歉 – 2013-04-22 14:59:16