0

你好,这对我来说很好,但我认为它可以更简单任何人都可以帮助我使用这段代码来检查用户输入的时间和日期

    function ckeck_date($sug_date, $sug_time)
    {
        if ($sug_date[0] == NULL)
        {
            return TRUE;
        }
        else
        {
            for ($i = 0; $i < count($sug_date); $i++)
            {
                if ($this->_totimestamp($sug_date[$i], $sug_time[$i]) < mktime(23, 59, 59, date('m'), date('d') - 1, date('Y')))
                {
                 $x=false;
                }
                else $y=true;
            }

        }
        if(isset($x))
        {
        return $x*$y;
        } 
else return true;

    }
4

2 回答 2

2

试试这个,把你的日期和时间

 $str = '2012-06-15 11:12:23'; // OR '15-06-2012 11:12:23'

if ( strtotime( $str ) > time( ) ) {
  // Your time is greater than current time
}
于 2012-06-03T08:50:51.433 回答
0

对于日期,您可以使用:

检查日期

使用strtotime您可以int从字符串创建并比较它们是否在将来(如果您比较now

$today = strtotime(date("Y-m-d")); // today's date
$userd = strtotime("2012-10-16");  // users input

if ($userd > $today){ 
   $valid = "yes"; 
} else { 
   $valid = "no"; 
}

如果我是对的,您也可以将时间添加到输入中,但是您需要检查有关此的 php 文档以获取正确的日期时间格式

更短:

if (strtotime($userdate) > strtotime(date("Y-m-d"))){ 
   $valid = "yes"; 
}
于 2012-06-03T08:33:07.790 回答