Need help on constructing SQL query.

Discussion in 'MySQL' started by fatabbot, Dec 30, 2006.

  1. #1
    hello, i have a table with a DATETIME column... I want to do a SELECT of all records from a specific month of the year.

    So something like with this pseudo code:

    SELECT * FROM table WHERE datecolumn = OCTOBER 2006
     
    fatabbot, Dec 30, 2006 IP
  2. trevlar

    trevlar Peon

    Messages:
    65
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To return results for anything from October (Oct '04, '05, or '06)...

    SELECT * FROM table WHERE MONTH(datecolumn) = 10
    Code (markup):
    To return results for October of 2006:

    SELECT * FROM table WHERE MONTH(datecolumn) = 10 AND YEAR(datecolumn) = 2006
    Code (markup):
    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
     
    trevlar, Dec 31, 2006 IP