ItSolutionStuff.com

PHP Check If Current Date is Between Two Dates Example

By Hardik Savani • May 14, 2024
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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Convert String to Date in PHP?

Read Now →

PHP MySQL DataTables Server-side Processing Example

Read Now →

How to Change Date Format in JQuery?

Read Now →

PHP CRUD Operation Using Ajax and JQuery Example

Read Now →

PHP Capture Screenshot of Website from URL Example

Read Now →

PHP Remove Duplicates from Multidimensional Array Example

Read Now →

PHP JQuery Select2 Ajax Autocomplete Example

Read Now →

How to Get Folder Path from File Path in PHP?

Read Now →

How to Remove White Space from String in PHP?

Read Now →

How to Get a Current Page URL in PHP?

Read Now →

How to Convert Array Key to Lowercase in PHP?

Read Now →

How to Generate Random Alphanumeric String in PHP?

Read Now →

How to access PHP variables in JQuery?

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →