使用now()日期和插入时间进行php验证

使用now()日期和插入时间进行php验证,php,Php,嗨,我现在被一个php验证卡住了,我正试着根据 日期();date以确保日期为当前日期,并且不允许任何小于当前日期的日期() 可以使用datetime diff函数将您的日期与now()进行比较: 希望这有帮助 类似的方法应该可以使用(假设日期的格式为YYYY-MM-DD): 函数是有效的未来日期($date) { if(false==strottime($date)) { 返回false; } 列表($year、$month、$day)=分解('-',$date); if(false==检查日

嗨,我现在被一个php验证卡住了,我正试着根据 日期();date以确保日期为当前日期,并且不允许任何小于当前日期的日期()


可以使用datetime diff函数将您的日期与now()进行比较:


希望这有帮助

类似的方法应该可以使用(假设日期的格式为
YYYY-MM-DD
):

函数是有效的未来日期($date)
{
if(false==strottime($date))
{
返回false;
}
列表($year、$month、$day)=分解('-',$date);
if(false==检查日期($month,$day,$year))
{
返回错误
}
$now=新日期时间();
$compare=新日期时间($date);
如果($compare<$now)
{
返回false;
}
}
公共函数checkDateField($month、$day、$year){
如果(!is_numeric($month)| |!is_numeric($day)| |!is_numeric($year)返回“无效日期”;
if(strotime($year.'-'.$month.'-'.$day.'23:59:59')
听到这个消息我很难过。你的问题是什么?
检查日期($month,$day,$year)>time()
我必须测试$month$day$year与当前的Now()日期的对比,确保它更大或者发送的是invalidDate是的。我读了4遍,速度很慢,仍然看不到问题。据我所知,“Now()”是一个MySQL函数,但我也没有看到它的任何引用。也许你的意思是“time()”?编辑:好的,我不确定这不是你想要的。要不要解释一下?
 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;    
       }
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;
    }
}
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';
    }

}