View Single Post
Old 03-14-2009, 03:48 PM   #4 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Assuming that dateA and dateB are unix timestamps representing dates where dateA < dateB, this should work:

PHP Code:
//1 day = seconds/hours in day/minutes in hours/seconds in minute)
//Floor because it will be the lowest integer
$startDay floor($dateA/24/60/60);
$endDay =  floor($dateB/24/60/60);
$daysDiff $endDay-$startDay
for($i=0;i<$daysDiff;$i++)
{
//This is the start date plus $i days.
$day Date("y-m-d",$startDay*24*60*60+$i*24*60*60)

Basically what this does is:
Convert timestamp A into days
Convert timestamp B into days
Get the difference
Starting from the first day, represent that day plus 0 to the difference.

It would, however, be more efficient to store the start date and the end date in the database and have the script (or the query) generate your dates opposed to inserting each one.
__________________

Village Idiot is offline  
Reply With Quote