Select where timestamp is today statement

Discussion in 'PHP' started by Silver89, May 25, 2010.

  1. #1
    I'm trying to create a query that selects values that were inserted in today's date. The values are stored as raw dates in the following format:

    2009-03-30 05:22:03

    So far I've come up with the following but not sure how to progress? Where I'm not sure what's needed I've simply put it in words.

    
    mysql_query("SELECT count(id) FROM table WHERE UNIX_TIMESTAMP(time) = today");
    
    PHP:
    Thanks in advance.
     
    Silver89, May 25, 2010 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    This should work...

    mysql_query("SELECT count(id) FROM table time = " . date("Y-m-d"));
    PHP:
     
    digitalpoint, May 25, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Assuming 'time' is your datestamp field in the format you quoted;

    mysql_query("SELECT count(id) FROM table WHERE date(time) = date(now())");
    PHP:
     
    lukeg32, May 26, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Will the OP ever be able to select that ?

    The time will never match ?

    Wouldn't the OP need a Start date, time and an End date, time ?

    EDIT:

    Try something like this to start with and let us know the results:

    mysql_query("SELECT count(id) FROM table WHERE date(time) = date(NOW() - INTERVAL 1 DAY )");
    PHP:
    or
    mysql_query("SELECT count(id) FROM table WHERE timestamp = (NOW() - INTERVAL 1 DAY )");
    PHP:
     
    Last edited: May 26, 2010
    MyVodaFone, May 26, 2010 IP
  5. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Thats why its cast as a date and not a timestamp .......
     
    lukeg32, May 26, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    mysql_query("SELECT count(id) FROM table WHERE time = " . date("Y-m-d"));
    PHP:
     
    danx10, May 29, 2010 IP