SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql date range problem.

    For example 2 coloums start and finish

    2 dates

    start = 2010-05-23
    finish = 2010-07-26

    I want to get all days like 2010-05-23,2010-05-24 etc.

    can I do it with mysql or should I use php

    thank you.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You want to generate all dates between a start and end point stored in a database, not find all rows between two dates, right?

    I think doing that in your programming language would be more appropriate.

    PHP Code:
    $sql "SELECT start, finish FROM sometable";
    $result mysql_query($sql);
    $row mysql_fetch_array($result);

    for (
    $i strtotime($row['start']); $i <= strtotime($row['finish']); $i += 24*60*60) {
        echo 
    date('Y-m-d'$i) . "<br />";


  3. #3
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you but. this that calculate months with 30,31 or for example february 28 or 29?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes.

    It is adding 24 hours at a time to a UNIX timestamp beginning at your start date and ending on your finish date.

    date() converts the timestamp to a formatted string and handles all the calculations.

  5. #5
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you again


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
  •