2014-10-29 86 views
0

我正在使用這個腳本來比較php中的兩個日期列。我有圖像的文件夾,並希望根據他們的日期合併所有圖像到一個XML。圖像格式爲 「entry_145_BD12ZZU_2014-06-25_12-26-58」 的.jpg比較兩個日期值不是時間在php

if(file_exists($xmlFullFilename)) { 
if($entryTimeNode->format("Y-m-d") = $entryTimeNode->format("Y-m-d"))** this is what I tried. 
      $xmlDoc = new DomDocument(); 
      $tmp = split(" ", $entryTime); 
     $dateString = $tmp[0] . "T" . $tmp[1]; 
     $entryTimeNode = $xmlDoc->createElement("EntryTime", $dateString); 

XML文件

<Incidents xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Count="2" Date="2014-10-24" Time="12:05:39" FileName="2014-10-24_Brook_Retail_Park.xml"> 
     <Incident> 
     <EntryTime>**2014-10-17**T11:17:44</EntryTime> 
     </Incident> 
    <Incident> 
<EntryTime>**2014-10-17**T16:19:15</EntryTime> 
</Incident></Incidents> 
+2

我有點在這個問題所有的代碼混淆。它與你比較兩個日期的問題有什麼關係?你能讀取文件中的值嗎?如果是這樣,唯一存在的問題是,*「我有兩個字符串(從XML文件讀取),比如** 2014-10-17 ** T11:17:44''和** ** 2014- 10-17 ** T16:19:15'',我只想使用日期部分(沒有時間)比較它們,我已經嘗試過......「* – GolezTrol 2014-10-29 12:40:32

+0

嗨,Golez,我只需要合併所有文件日期到一個XML文件。 – 2014-10-29 12:43:08

+0

仍然不清楚問題是什麼。你是否堅持比較,合併......請縮小一點。 – GolezTrol 2014-10-29 12:46:01

回答

0
mostly date also compare with as like normal variable like: 

$a=5; 
$b=10; 
if($a > $b){ 
//Blalala 
} 

and in date also you can compare like this 
$c=2014/10/29; 
$d=2014/10/29; 
if($c > $d){ 
//Blalala 
} 

and i can't more figure out from question you have date with time so in your case, 
$e=**2014-10-17**T11:17:44 
$f=**2014-10-17**T16:19:15 

$first_date_ary=explode("**", $e); 
$second_date_ary=explode("**", $f); 

and then compare your date, as per i mention above 
if($first_date_ary[0] > $second_date_ary[0]){ 
//Blalala 
} 

and sorry for bad English too. 
+0

感謝Manoj我會盡力的。 – 2014-10-29 13:29:17