I have a billing system where users are allowed to renew if the expiry date is less than 1 month away.
For example, let's say a product expires on 03/10/2019. Today's date is 04/09/2019 so it's within the 30-day window and will be shown the message to renew. However, Monday's date (02/09/2019) or any date before that is not within the 30-day window and won't be shown the message.
Bearing in mind I'm using the UK date system DD-MM-YYYY.
Managed to construct an if statement to check if the current date is exactly 1 month away from the specified date but not within that time, which is what I need to do.
Scoured Google for this and could not find an answer. I might just be searching for the wrong thing, I don't know.
$current_date = date("d-m-Y");
$expiry_date = date_create("04-10-2019");
$month_prior_date = date_sub($expiry_date, date_interval_create_from_date_string("1 month"));
$month_prior_date = date_format($month_prior_date, "d-m-Y");
if ($current_date == $month_prior_date) {
echo "You are eligible for a renewal.";
}
Aucun commentaire:
Enregistrer un commentaire