Skip to content

Instantly share code, notes, and snippets.

@imvision
Created September 17, 2013 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imvision/6592919 to your computer and use it in GitHub Desktop.
Save imvision/6592919 to your computer and use it in GitHub Desktop.
Function to find all dates between two given dates
<?php
/**
* function to calculate all dates between two dates
*
* @param date $first
* @param date $last
* @param string $step
* @param string format
*
* @return array
*/
function dateRange( $first, $last, $step = '+1 day', $format = 'Y-m-d' )
{
$dates = array();
$current = strtotime($first);
$last = strtotime($last);
while( $current <= $last )
{
$dates[] = date($format, $current);
$current = strtotime($step, $current);
}
return $dates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment