Display Dates between from date to date

Discussion in 'PHP' started by newphpcoder, Feb 12, 2012.

  1. #1
    Hi...

    Good day!

    I have table that has a field from_date and to_date.

    Now I just want to know if how can I display as table format the dates between from_date to_date.

    Like this

    from_date: 2011-12-16
    to_date: 2011-12-31

    I want to display it:

    16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 // table format.

    Thank you
     
    newphpcoder, Feb 12, 2012 IP
  2. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #2
    Something like this should do the trick, though it breaks if days are in single characters eg: if 7th was just 'Y-M-7' ,
    format needs to be 'Y-M-07'


    
    <?php
    //----------------------------------------------------------------------------------------
    function dates_range($dateA, $dateB) {
       if ($dateA<$dateB) {
           $dates_range[]=$dateA;
           $dateA=strtotime($dateA);
           $dateB=strtotime($dateB);
           while ($dateA!=$dateB)
           {
               $dateA=mktime(0, 0, 0, date("m", $dateA), date("d", $dateA)+1, date("Y", $dateA));
               $dates_range[]=date('Y-m-d', $dateA);
           }
       }
       return $dates_range;
    }
    //----------------------------------------------------------------------------------------
    /* usage: */
    $from_date = "2011-12-16"; #Note: days need two digits eg: for 7th would be: 07 etc. 
    $to_date = "2011-12-31";
    
    $array = dates_range($from_date, $to_date);
    foreach($array as &$val) {
    $val = substr($val, -2); #extract days (last two chars)
    }
    unset($val); #free up buffer
    echo implode(" ", $array);
    ?>
    
    PHP:
     
    ROOFIS, Feb 12, 2012 IP
  3. landlordtoday

    landlordtoday Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    • select COUNT(UserID) from prayer WHERE date BETWEEN CURDATE() and DATE_SUB(CURDATE(),INTERVAL -14 DAY);
    Update this query....as per your requirement....
     
    landlordtoday, Feb 15, 2012 IP