get all dates between two dates php – How to Get All Dates Between Two Dates in PHP?

get all dates between two dates php and display it. The PHP date function is used to format a date. here we can learn to main 2 Examples.

get all dates between two dates php

Get All Dates Between $Two Dates can be done in many ways. The following source code will get all dates between two dates php.

Example:

how_to_get_all_dates_between_two_dates_in_php.php

<?php
      
    function getBetweenDates($joinDt, $endDate)
    {
        $rangArray = [];
            
        $joinDt = strtotime($joinDt);
        $endDate = strtotime($endDate);
             
        for ($activeDt = $joinDt; $activeDt <= $endDate; 
                                        $activeDt += (86400)) {
                                                
            $myJoinDt = date('Y-m-d', $activeDt);
            $rangArray[] = $myJoinDt;
        }
  
        return $rangArray;
    }
  
    $myJoinDts = getBetweenDates('2022-11-01', '2022-11-10');
     
    print_r($myJoinDts);
  
?>

Don’t miss : Calculate Age From Date Of Birth In PHP

Also Read This πŸ‘‰   MySQL Remove special characters from database

Result

Array
(
    [0] => 2022-11-01
    [1] => 2022-11-02
    [2] => 2022-11-03
    [3] => 2022-11-04
    [4] => 2022-11-05
    [5] => 2022-11-06
    [6] => 2022-11-07
    [7] => 2022-11-08
    [8] => 2022-11-09
    [9] => 2022-11-10
)

I hope you get an idea about get all dates between two dates php.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.