|
-
Nov 11th, 2005, 03:20 PM
#1
Thread Starter
Lively Member
Build Array of all Dates between two Dates
Hello all.
I am trying to build an array of all dates between two other dates. Though I don't know how to go about it.
Any help is appreciated.
Thanks.
Code:
$check_in_date = strtotime($_POST['check_in_month'].'/'.$_POST['check_in_day'].'/'.$_POST['check_in_year']);
$check_out_date = mktime(0, 0, 0, $_POST['check_in_month'], ($_POST['check_in_day']+$_POST['nights']), $_POST['check_in_year']);
// build array of all dates between $check_in_date and $check_out_date
-
Nov 22nd, 2005, 06:57 PM
#2
Hyperactive Member
Re: Build Array of all Dates between two Dates
PHP Code:
$check_in_date = strtotime($_POST['check_in_month'].'/'.$_POST['check_in_day'].'/'.$_POST['check_in_year']);
$check_out_date = mktime(0, 0, 0, $_POST['check_in_month'], ($_POST['check_in_day']+$_POST['nights']), $_POST['check_in_year']);
// build array of all dates between $check_in_date and $check_out_date
//Get the difference between the two dates
$diff = $check_out_date-$check_in_date;
//Change seconds to days
$diff = $diff/60/60/24;
$dates;
//iterate through the days
for ($i=1;$i<=$diff;$i++) $dates[] = $check_in_date + ($i*60*60*24);
//Display
foreach ($dates as $dt) echo (date("Y-m-d",$dt).'<br>');
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|