2012-02-17 42 views
0
function is_due($due_date) 
     { 
      $now=new DateTime('now'); 
      $dnow=$now->format('Y-m-d'); 
      $due=$due_date->format('Y-m-d'); 
      $interval =(strtotime($dnow)-strtotime($due)); 
     print_r($due_date->format('Y-m-d')); 
     return $interval; 
     } 

我使用该功能,以检查是否给定的日期是由于检查日期时间失败?

的$ DUE_DATE从外部文件被分配作为数组的字符串“2012年12月12日”被检索后经过在元素,例如,

$ datetime ['due'] = ReadExtFile(); 当我调用该函数为print_r(is_due($datetime['due']));

$due=new DateTime($datetime['due']); 

似乎没有任何工作,我看不到输出。但print_r($datetime)将显示[due]的结果。

+0

如果你做print_r(is_due($ datetime)),会发生什么? – MysticXG 2012-02-17 04:26:15

+0

嗯。为什么是时间? '$ interval = $ now-> getTimeStamp() - $ due_date-> getTimeStamp()'。 – 2012-02-17 04:38:43

+0

谢谢你现在的作品。 – Mikhail 2012-02-17 04:41:31

回答

0

这种方法写入的方式,它期望$ due_date是一个DateTime对象,而不是一个字符串。您表示您传递的是字符串而不是对象。

看起来你只是想返回$ interval作为从给定的日期到现在的计数。我建议只使用一个只处理字符串的简单方法。

function is_due($due_date) { 
    return time() - strtotime($due_date); 
    // return ((time() - strtotime($due_date)) >= 0); // depending on function you want this might work 
}