Reputation: 109
php compare two dateTime object with comparision perator which is >(greater than).Below code is given
$date1=new DateTime("07-03-2010");
$date2=new Datetime("21-09-2015");
if($date1>$date2)
{
echo "two datetime object has compared";
}
Above code give correct result.My question is how two Datetime object is compared with comparision operator in php
Upvotes: 2
Views: 390
Reputation: 311
Actually in PHP, when we store dates in a variable, it doesn't stored in any format. rather it is stored in seconds i.e. the difference between your given date and a reference date that is defined by PHP. I don't exactly remember the reference date, you may google it.
So, when you compare dates, it actually compares seconds.
Look at this,
Upvotes: 0
Reputation: 224913
DateTime
is a builtin and can overload operators. (This isn’t possible in PHP… yet.)
I think the relevant line is ext/date/php_date.c:1995.
Upvotes: 3