I have a date time value which is coming from the database. The value will be a date time with microseconds like 2014-03-18 10:34:10.938
. Now i have to compare it with a same value which is also a microseconds date time value from the database. I have tried with strtotime
but it is not considering the microseconds value.
So anybody can suggest a way to compare these values.
I tried the following:
$val1 = '2014-03-18 10:34:10.938';
$val1 = '2014-03-18 10:34:10.800';
if(strtotime($val1) > strtotime($val2))
//some code
else
//some code
Also i tried without using the strtotime
$val1 = '2014-03-18 10:34:10.938';
$val1 = '2014-03-18 10:34:10.800';
if($val1 > $val2)
//some code
else
//some code
Method 2 get successes.So my question is am i using the correct way.?
EDIT
As per duplicate marking by @showdev i have tried the following
$val1 = '2014-03-18 10:34:09.999';
$val2 = '2014-03-18 10:34:09.940';
if(new DateTime($val1) > new DateTime($val2))
echo "1 is bigger";
else
echo "2 is bigger";
//Always output 2 is bigger unless i change $val1 seconds value