Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

display date period between two date php

/**
 * takes two dates and returns an array of dates between them
 * 
 * @param date1 The start date of the period.
 * @param date2 The end date of the period.
 * @param format The format of the date you want to display.
 * 
 * @return array array of dates between the two dates.
*/
function displayDatePeriod( $date1, $date2 , $format = "Y-m-d"){

    $periodArray = [];
    $period = 
      new DatePeriod(
      new DateTime($date1),
      new DateInterval('P1D'),
      new DateTime($date2)
    );

    foreach ($period as $key => $value) {
      $periodArray[] = $value->format($format) ;      
    }
  
  	$periodArray[] = $date2 ;

    return $periodArray;
}
1
 
PREVIOUS NEXT
Tagged: #display #date #period #date #php
ADD COMMENT
Topic
Name
5+4 =