PHP Check If Current Date is Between Two Dates Example

By Hardik Savani November 5, 2023 Category : PHP

In this example, i want to share with you small example of how to check current date is between startdate and enddate in php. we will check if today date is between two dates in php. we can simply check if current date is between two dates in php.

I written it very simple way so you can also use with laravel, codeigniter, zend php framework also. it's core php code for check if date is between two dates php.

Many times we require to check current date is between given two dates or not for subscription, trial, user expire time etc. so when user will register at that time will decide when he will expire and we will check it with current date always. so might be this post can help you to check if date exists between two dates in php.

You can check bellow simple example so it can help you.

Example:

<?php

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

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

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

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

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 09/10/2019 than it will return bellow output:

Output:

Current date is between two dates

I hope it can help you...

Tags :
Shares