Date Calculation to select all data for a week

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jessDMiller
    New Member
    • Dec 2006
    • 6

    Date Calculation to select all data for a week

    I need to output data for today and the following week.

    Here is what I have:

    [PHP]// Get all the data from the table
    $result = mysql_query("SE LECT * FROM $table where curdate() >= day AND curdate() < DATE_ADD(curdat e(),INTERVAL 7 day);")
    or die(mysql_error ());


    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_arr ay( $result )) {
    // Print out the contents of each row into a table
    }[/PHP]

    I have also tried:

    [PHP]// Get all the data from the table
    $result = mysql_query("SE LECT * FROM $table where curdate() >= day AND curdate() < day + 7;")
    or die(mysql_error ());


    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_arr ay( $result )) {
    // Print out the contents of each row into a table
    }[/PHP]

    Both of these only output the data with where day = curdate()

    day is set to the date type with the default as 0000-00-00

    i have mySQL 4.1.15

    once again, I need to output data for today and the following week

    thanks
  • ScarletPimpernal
    New Member
    • Mar 2007
    • 39

    #2
    Try this query ...

    SELECT * from tablename where DATE_FORMAT(fie ldname,'%m') <= DATE_FORMAT(Cur DATE(),'%m');




    Thanks,
    Scarlet

    Comment

    • jessDMiller
      New Member
      • Dec 2006
      • 6

      #3
      That worked to get everything out of the database but how do I then do the AND part - so I get todays info out and then the info for the next 7 days and nothing past the next seven days out?

      So today I would want to see 2007-04-06 through 2007-04-13 info

      tomorrow I would want to see 2007-04-07 through 2007-04-14 info

      etc...

      Thanks for the help so far!

      Comment

      • jessDMiller
        New Member
        • Dec 2006
        • 6

        #4
        Problem Solved!!

        [PHP]"SELECT * from $table where day BETWEEN CURDATE() AND DATE_ADD(curdat e(),INTERVAL 7 day);"[/PHP]

        Thanks for any help!

        Comment

        Working...