0

I have to check expiry date is passed with current date and then disable the link. Should i convert strtotime function and check or is there any simple way to check it. We should not compare the dates

$current_date = "2018-07-23 12:00:00";
$expiry date = "2018-07-22 12:00:00";

if($expiry date>$current_date){
$link = "<a href="http://www.example.com";
} else {
$link = "#";
}
nick
  • 39
  • 5
  • php can read this via `strtotime()`.. it will become a simple number then in seconds since 1970 if i am not mistaken. (it counts in seconds since january 1st 1970). since it becomes a number, you can compare these 2 numbers – Dorvalla Jul 13 '18 at 13:58

1 Answers1

1

I would use strtotime() as follows:

$current_date = "2018-07-23 12:00:00";
$expiry date = "2018-07-22 12:00:00";

if (strtotime($expiry date) > strtotime($current_date)) {
       $link = "<a href="http://www.example.com";
} else {
       $link = "#";
}
mlewis54
  • 2,372
  • 6
  • 36
  • 58