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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With