SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question dates between two date

    Hi

    How to get list of dates between two dates?
    in this format (2012-5-21)

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That is a very popular question. Google that and it turns up numerous results. This one is at the top of the list:

    http://biostall.com/get-a-list-of-da...dates-with-php

    EDIT: found an error testing the script, the example shown should be something like this:
    PHP Code:
    <?php
        
    // Specify the start date. This date can be any English textual format  
        
    $date_from "2012-4-21";  
        
    $date_from strtotime($date_from); // Convert date to a UNIX timestamp  
          
        // Specify the end date. This date can be any English textual format  
        
    $date_to "2012-5-21";  
        
    $date_to strtotime($date_to); // Convert date to a UNIX timestamp  
          
        // Loop from the start date to end date and output all dates inbetween  
        
    for ($i=$date_from$i<=$date_to$i+=86400)
        {
            echo 
    date("Y-m-d"$i).'<br />';  
        }  
    ?>
    Can’t take things from the internet for granted


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •