如何检查此日期格式是否在将来?

时间:2013-05-28 09:06:44

标签: php

我的约会时间与01/05/2013 12:44一样。如果将来这个日期时间如何检查php?

4 个答案:

答案 0 :(得分:1)

试试这个:

<?php

$dt = '01/05/2013 12:44';
$nowdt = time();
$diff = strtotime($dt) - $nowdt;
echo $diff;
if($diff > 0){
 echo (" your date is future date");
} else {
    echo ("your date is is not future date");
}
?>

答案 1 :(得分:0)

您可以将time()与该日期的UNIX时间戳表示进行比较:

if (time() < strtotime("01/05/2013 12:44"))
{
    // your time is greater than todays date
}

另一种方式

$time = strtotime(str_replace("/","-",$date) )
if ($time > time())
{
  echo "$date is in the future."
}

答案 2 :(得分:0)

从PHP手册中使用mktime

伪代码中的示例:

$today     = mktime("today");
$your_date = mktime("...");

if ($your_date > $today) {
    // it's in the future
}

答案 3 :(得分:0)

转换为Unix时间,然后查看它是否大于当前时间。

<?php
if(strtotime("01/05/2013 12:44") > time()) {
 //time is in the future.
}else{
  //time is in the past
}
?>