In this post, I would like to tell you about “How to Check Current Date is between two Dates in PHP”.

First of all we need two dates which needs to check, start date and end date. Then we will check them if today date is between those two dates or not using PHP.

It can be implemented in any simple PHP code. For now, I am not using any framework. I am using Core PHP to make it simple and clear.

Mostly we used it to check two dates for subscription, trial, user expiration etc. So, when user will register. At that time we will decide when he will expire and we will check it with current date always to ensure we are in real mode.

You can check bellow simple and smart efficient example:

Example:


<?php

$currentDate = date('Y-m-d');

$currentDate = date('Y-m-d', strtotime($currentDate));

$startDate = date('Y-m-d', strtotime("01/01/2020"));

$endDate = date('Y-m-d', strtotime("01/02/2020"));

if (($currentDate >= $startDate) && ($currentDate <= $endDate)){

    echo "Current date is between two dates";

}else{

    echo "Current date is not between two dates";  

}
?>

If current date is 20/01/2020 then it will print bellow output:

Output:

Current date is between two dates

I hope it will helps you to figure out “How to Check Current Date is between two Dates in PHP”. If you found that article useful then don’t miss to click on share this post with others by clicking on share button

LEAVE A REPLY

Please enter your comment!
Please enter your name here