Sunday, 15 February 2015

php - compare date only part from the string -



php - compare date only part from the string -

i have 2 strings (read xml file), '2014-10-17t11:17:44' , '2014-10-17t16:19:15'. want compare them using date part (without time). tried ...script below

if(file_exists($xmlfullfilename)) { if($entrytimenode->format("y-m-d") = $entrytimenode->format("y-m-d")){ ( appends exisiting file ....) $xmldoc = new domdocument(); $tmp = split(" ", $entrytime); $datestring = $tmp[0] . "t" . $tmp[1]; $entrytimenode = $xmldoc->createelement("entrytime", $datestring); } else { //create new xml file . }}

xml file

<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-17t11:17:44</entrytime> </incident> <incident> <entrytime>2014-10-17t16:19:15</entrytime> </incident></incidents>

my soluction is

$date = "2014-10-17t11:17:44"; $date2 = "2014-10-17t16:19:15"; $date = new datetime($date); $date2 = new datetime($date2); $diff = $date->diff($date2); if((int)$diff->format('%y%m%d')==0) { // dates equal }

php

No comments:

Post a Comment