PHP’s date function strtotime () solves the problem of comparing dates and to check whether the user entered date/custom date is expired or not.

Inorder to check whether, the custom date is expired or not, we need to do the following steps

  1. Get today’s date.
  2. Get the date to be checked.
  3. Convert the dates to Unix Timestamp using strtotime() function.
  4. Use if statement to compare the Unix Timestamps of both the dates.
  5. If the custom date Unix Timestamp is greater than the Current date’s Unix Timestamp, then the custom date is not expired. If it is less, then it is expired.

A sample simple code is,

$custom_date = "15-08-2008";
$todays_date = date("d-m-Y");

$today = strtotime($todays_date);
$cus_date = strtotime($custom_date);

if ($cus_date > $today) {
     $has_expired = "yes";
} else {
     $has_expired = "no";
}

Subscribe to our Newsletter

Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam. View newsletter

Add your comment No Comments so far

By using this website, you agree to our Terms

Share