
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Return all dates between two dates in an array in PHP
To return all dates between two dates, the code is as follows −
Example
<?php function displayDates($date1, $date2, $format = 'd-m-Y' ) { $dates = array(); $current = strtotime($date1); $date2 = strtotime($date2); $stepVal = '+1 day'; while( $current <= $date2 ) { $dates[] = date($format, $current); $current = strtotime($stepVal, $current); } return $dates; } $date = displayDates('2019-11-10', '2019-11-20'); var_dump($date); ?>
Output
This will produce the following output−
array(11) { [0]=> string(10) "10-11-2019" [1]=> string(10) "11-11-2019" [2]=> string(10) "12-11-2019" [3]=> string(10) "13-11-2019" [4]=> string(10) "14-11-2019" [5]=> string(10) "15-11-2019" [6]=> string(10) "16-11-2019" [7]=> string(10) "17-11-2019" [8]=> string(10) "18-11-2019" [9]=> string(10) "19-11-2019" [10]=> string(10) "20-11-2019" }
- Related Articles
- How to store all dates in an array present in between given two dates in JavaScript?
- How to list all dates between two dates in Excel?
- Sort an array of dates in PHP
- Comparing two dates in PHP
- PHP program to compare two dates
- How to create a vector with dates between two dates in R?
- Calculate minutes between two dates in C#
- Find objects between two dates in MongoDB?
- PHP program to sort dates given in the form of an array
- Comparison of dates in PHP
- Perform MySQL search between two dates
- How to query between two dates in MySQL?
- MySQL query to select all data between range of two dates?
- How to count days between two dates in Java
- Select the date records between two dates in MySQL

Advertisements