James Stone
asked on
determine all the dates between a start and end date.
I am trying to build a form (using PHP) and would like to have a start date (entered as 3 fields - startMonth, startDay, and startYear) and an end date (entered as 3 fields - endMonth, endDay, endYear).
If they pick the same day for both I am ok, but if the end date is 3 days later I have to figure what dates are in between.
Example 12/20/2003 - 12/23/2003, would have 12/20/2003 and 12/21/2003, and 12/22/2003, and 12/23/2003. (4 dates)
I am pretty new to programming, so an example would be helpful.
Thanks
If they pick the same day for both I am ok, but if the end date is 3 days later I have to figure what dates are in between.
Example 12/20/2003 - 12/23/2003, would have 12/20/2003 and 12/21/2003, and 12/22/2003, and 12/23/2003. (4 dates)
I am pretty new to programming, so an example would be helpful.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
going with lozloz's initial range checking and assignments using mktime, here's another way to loop through the dates which I think might be a little more readable when you come back to do some debugging:
while ($startdate <= $enddate)
{
echo date("mdy", $startdate);
$startdate = strtotime("+1 day", $startdate);
}
while ($startdate <= $enddate)
{
echo date("mdy", $startdate);
$startdate = strtotime("+1 day", $startdate);
}
ASKER
Thanks, I am teaching my self php (I've worked with databases for a few years). The less typing the better! It is much easier to read and probably more efficient too.
Just realized I never gave lozloz his points for helping.
james
Just realized I never gave lozloz his points for helping.
james
ASKER
first time I had seen floor function so read up on that.
Thanks for the comment - eventually I will figure this stuff out.
<?
$distance = $distance / 60 / 60 / 24;
$distance = floor($distance);
echo $distance."<p>";
//
// loop through the days
$range = range (0, $distance);
foreach ($range as $value) {
$Rangetimestamps = mktime(0,0,0,$_POST["Start
$RangeDates = date("mdy", $Rangetimestamps);
//echo $Rangetimestamps. " and ".$value."<p>";
echo $RangeDates."<p>";
}
?>