Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php strtotime does not work

I got an issue on below script, assume $exp_date is retrieved from db, I want to compare expiry date with today date to check whether membership's is still alive.

There is nothing to display but only Time Expired, what's wrong with the code?

The data retrieved from expiry column in db is set as varchar (which is built by ex-colleague).

$exp_date = "22/01/2014";
$todays_date = date("d/m/Y");
$today = strtotime($todays_date); 
$expiration_date = strtotime($exp_date);
echo $expiration_date.' | '.$today.'<br>';
if($expiration_date > $today){ 
    echo 'Still Active';
} else { 
    echo 'Time Expired';
}

Anyone can help with?

like image 799
conmen Avatar asked Nov 30 '22 04:11

conmen


1 Answers

Here is working code

 <?php
 $exp_date = "22/01/2014";
  $exp_date = str_replace('/', '-', $exp_date);
  $todays_date = date("d-m-Y");
  $today = strtotime($todays_date); 
  $expiration_date = strtotime($exp_date);

  echo $expiration_date.' | '.$today.'<br>';

  if($expiration_date > $today){ 
      echo 'Still Active';
  } else { 
      echo 'Time Expired';
  }
?>

Actually strtotime() does not work with format 'd/m/Y'

hope it helps you.

like image 166
alwaysLearn Avatar answered Dec 04 '22 10:12

alwaysLearn