I have a string and want to convert it into a date and then perform some compare and do some action. This is my scenario:
$a="2015-02-17" //yyyy-mm-dd
$b="2015-01-17" //yyyy-mm-dd
if ($a>$b)
{
//action1
}
else
{
//action2
}
I have a string and want to convert it into a date and then perform some compare and do some action. This is my scenario:
$a="2015-02-17" //yyyy-mm-dd
$b="2015-01-17" //yyyy-mm-dd
if ($a>$b)
{
//action1
}
else
{
//action2
}
$today = '2015-02-17';
$expire = '2015-01-01';
$today_time = strtotime($today);
$expire_time = strtotime($expire);
if ($expire_time < $today_time) {
//do some thing
}
If you are using PHP 5 >= 5.2.0, you could use the DateTime class:
$date1 = new DateTime($today);
$date2 = new DateTime($expire);
if ($date1 < $date2) { /* Do something */ }