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
- Get today’s date.
- Get the date to be checked.
- Convert the dates to Unix Timestamp using strtotime() function.
- Use if statement to compare the Unix Timestamps of both the dates.
- 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";
}
Add your comment No Comments so far