Thursday 17 July 2014

Compare date in php

It’s really a horrible thing to work on date to being a programmer. If language is PHP then it’s too hard to achieve but don’t worry I have a best trick to solve it just take a look on following lines.

In PHP Date store in string format internally and time is store integer internally. You just have to change date into its equivalent time integer value and compare their integer as we work on number.

function compare_date($d1,$d2)
{
$date1=strtotime($d1);
$date2=strtotime($d2);
if($date1>$date2)
echo "First Date is greatest one";
else
echo "Second Date is greatest one";
}

I am using function for implement your logic you can work it where you want without using function 

No comments:

Post a Comment