Results 1 to 3 of 3

Thread: Function to return an array of dates...

  1. #1

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Unhappy Function to return an array of dates...

    Hi,

    I need a function that'll return an array containing all dates between a range of dates sent as parameters. For example:

    $array() = function('20/10/2005','31/01/2005');

    echo $array(0) would result: 20/10/2005
    echo $array(1) would be 21/10/2005
    echo $array(2) would be 22/10/2005, etc.

    is it possible?
    Last edited by _Yoyo; Oct 26th, 2005 at 03:05 PM.
    The biggest man you ever did see was once just a baby.

    Bob Marley

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Function to return an array of dates...

    How about something like this?

    PHP Code:
    <?php
        $array 
    getDatesBetween('10/01/2005','10/31/2005');

        for (
    $i 0$i count($array); $i++) {
            echo 
    $array[$i] . '<br />';
        }

        function 
    getDatesBetween($dateOne$dateTwo$format 'm/d/Y') {
            
    $return = array();
            if (
    strtotime($dateOne) > strtotime($dateTwo)) {
                return 
    $return// return blank array
            
    }

            
    $currDate $dateOne;
            
    $i 0;

            while (
    $currDate <= $dateTwo) {
                
    $return[] = $currDate;

                
    $i++;
                
    $currDate date($formatstrtotime($currDate ' +1 days'));
            }

            return 
    $return;
        }
    ?>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Function to return an array of dates...

    It doesn't work from one year to another. For instance, from 10/27/2005 to 28/01/2005 it'll only return 10/27/2005. Anyone?
    The biggest man you ever did see was once just a baby.

    Bob Marley

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