我想在php中的兩個日期時間之間的差異。我想在H:i:s格式中進行比較。這是我的代碼。是否有任何函數來查找日期和時間到日期時間在PHP中的區別?
$start_date = 2013-08-13;
$end_date = 2013-08-23;
$start_time = 12:28:58;
$end_time = 13:16:45;
$h1 = substr("$start_time",0,-6);
$i1 = substr("$start_time",3,-3);
$s1 = substr("$start_time",6);
$h2 = substr("$end_time",0,-6);
$i2 = substr("$end_time",3,-3);
$s2 = substr("$end_time",6);
$m1 = substr("$start_date",5,-3);
$d1 = substr("$start_date",8);
$y1 = substr("$start_date",0,-6);
$m2 = substr("$end_date",5,-3);
$d2 = substr("$end_date",8);
$y2 = substr("$end_date",0,-6);
$r1=date("Y-m-d H:i:s",mktime($h1,$i1,$s1,$m1,$d1,$y1));
$r2=date("Y-m-d H:i:s",mktime($h2,$i2,$s2,$m2,$d2,$y2));
你試過['DateTime'](http://php.net/datetime)嗎? –
y ...我試過但沒有工作。在日期時間我使用日期時間::差異,但我像這樣返回致命錯誤。 致命錯誤:調用未定義的函數date_diff()在c:\ wamp \ www \ website \ module \ 1 \ Save.php上第57行 –
也許在你的php版本中沒有DateTime類。 –