views:

27

answers:

2

I'm trying to find an existing helper function that will accept a start and end date and interval (day, week, month, year), and will return an array each day, week month or year in that range.

Would love to find a pre-existing one if it's out there.

Thanks!

A: 

In PHP 5.3 and later you can use DateInterval class for that

http://www.php.net/manual/en/class.dateinterval.php

Mchl
wow - that looks awesome. Unfortunately my script needs to support lower versions of PHP :/
Ian Silber
A: 

Here's a rough start:

function makeDayArray( $startDate , $endDate ){
 // Just to be sure - feel free to drop these is your sure of the input
  $startDate = strtotime( $startDate );
  $endDate   = strtotime( $endDate );

 // New Variables
  $currDate  = $startDate;
  $dayArray  = array();

 // Loop until we have the Array
  do{
    $dayArray[] = date( 'Y-m-d' , $currDate );
    $currDate = strtotime( '+1 day' , $currDate );
  } while( $currDate<=$endDate );

 // Return the Array
  return $dayArray;
}
Lucanos