ItSolutionStuff.com

How to Get All Dates Between Two Dates in PHP?

By Hardik Savani • May 14, 2024
PHP

Hi,

This example is focused on php get dates between two dates. you will learn how to get all dates between two dates in php. if you have question about return all dates between two dates in an array in php then i will give simple example with solution. if you want to see example of php get dates between two dates then you are a right place. follow bellow step for php date between range.

I will give you very simple example how to get dates between two dates in PHP. so let's see both example with output:

Example:

index.php

<?php

/**

* Write code on Method

*

* @return response()

*/

function getBetweenDates($startDate, $endDate)

{

$rangArray = [];

$startDate = strtotime($startDate);

$endDate = strtotime($endDate);

for ($currentDate = $startDate; $currentDate <= $endDate;

$currentDate += (86400)) {

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

$rangArray[] = $date;

}

return $rangArray;

}

$dates = getBetweenDates('2021-11-01', '2021-11-10');

print_r($dates);

?>

Output:

Array

(

[0] => 2021-11-01

[1] => 2021-11-02

[2] => 2021-11-03

[3] => 2021-11-04

[4] => 2021-11-05

[5] => 2021-11-06

[6] => 2021-11-07

[7] => 2021-11-08

[8] => 2021-11-09

[9] => 2021-11-10

)

i hope it can help you...

Tags: PHP
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 Check If Date is Future Date in PHP?

Read Now →

How to Check If Date is Past Date in PHP?

Read Now →

How to Get Month Name from Date in PHP?

Read Now →

How to Get Full Day Name from Date in PHP?

Read Now →

How to Get Previous Month from Date in PHP?

Read Now →

How to Get Next Month Date in PHP?

Read Now →

How to Get Tomorrow Date in PHP?

Read Now →

PHP Subtract Seconds from Time Example

Read Now →

How to Subtract Minutes from DateTime in PHP?

Read Now →

How to Subtract Hours from DateTime in PHP?

Read Now →