Results 1 to 2 of 2

Thread: Build Array of all Dates between two Dates

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    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

  2. #2
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372

    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(000$_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
  •  



Click Here to Expand Forum to Full Width