为什么我在PHP中比较两个日期不起作用?

为什么我在PHP中比较两个日期不起作用?,php,date,Php,Date,我已经删除了所需的输出和一些样式,因为它们不会影响问题。我似乎无法正确比较这两个日期,我的想法是,如果currentDate大于deadlineDate,则该路由将没有输出。我试图做的是阻止系统列出已经关闭的路由。我不明白为什么这么难,否则我就错过了一些基本的东西 <?php $driveDays = mysql_query("SELECT date,routeid from StopDates where routeid='".$row['id']."' ORDER BY date AS

我已经删除了所需的输出和一些样式,因为它们不会影响问题。我似乎无法正确比较这两个日期,我的想法是,如果currentDate大于deadlineDate,则该路由将没有输出。我试图做的是阻止系统列出已经关闭的路由。我不明白为什么这么难,否则我就错过了一些基本的东西

<?php
$driveDays = mysql_query("SELECT date,routeid from StopDates where routeid='".$row['id']."' ORDER BY date ASC");

while($stopDates = mysql_fetch_array($driveDays)){
$orderDaysBefore = $row['lastOrderDate']; // How many days before the order must be placed.

// Change the date taken from the query to new format 
$originalDate=($stopDates['date']);
$newDate = date("d.m", strtotime($originalDate));

// Count the deadline date for the route.
$deadlineDate = strtotime ("-".$orderDaysBefore." days +12 hours", strtotime ($originalDate)) ;
$deadlineDate = Date('d.m.y G:i', $deadlineDate);


//Get current date which is then compared to the deadline date. Idea is that if currentDate is larger than deadlinedate there will be no input.
$currentDate=Date("d.m.y G:i"); 


//The line below doesnt seem to be working, i have tried mktime and time too but for some reason it just cant compare.                              
if (strtotime($currentDate) > strtotime($deadlineDate)){
// Output nothing
}
else { ?>

<p>Output stuff here</p>


<?php
}
} 
?>

跳过格式设置,只需比较
strotime()

lastOrderDate
的结果,因为它不在查询中作为要返回的字段…您在字符串格式和时间戳格式之间做了太多的来回转换我很确定某个地方的格式转换正在出错…@Jared Farrish
lastOrderDate
来自不同的查询值是正确的。你不能调整查询以执行日期比较吗?@deceze可能是,我会研究一下。