mysql datetime range searching

Discussion in 'MySQL' started by alechua, Feb 7, 2010.

  1. #1
    Hi, i have a simple table to store a event duration and have 3 column in the table:
    starttime, endtime, event

    if i want to search for an event which happen between 2010-01-12 12:00:00 to 2010-01-13 12:00:00 on the data below:

    starttime endtime event
    2010-01-10 2010-01-14 Production
    2010-01-12 2010-01-13 Standby

    if i use the query:"select * from [table] where starttime >='2010-01-12' or endtime <='2010-01-13'" , i only manage to get the second row data, however, the first event ('production' in this case) also fall into this period of time, may i know is there any query that can use to search for data that occur in a specific time period? Thanks.
     
    alechua, Feb 7, 2010 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    $q = "SELECT * FROM table WHERE YEAR(date_field) = '2010' AND MONTH(date_field) = '01' AND DAY(date_field) = '12'";
     
    crivion, Feb 7, 2010 IP