Query regarding date range help needed

Discussion in 'MySQL' started by Dot_Net, Oct 13, 2011.

  1. #1
    Hello people

    I have two fields in table startdate and enddate , i want to fetch records between this two date including this dates. Can anyone give me query for this?
     
    Dot_Net, Oct 13, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    SELECT columns FROM my_table WHERE date_column >= 'INSERT_START_DATE' AND date_column <= 'INSERT_END_DATE';
     
    jestep, Oct 14, 2011 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    SELECT columns FROM my_table WHERE date_column BETWEEN 'START_DATE' AND 'END_DATE';

    is simpler. (Regardless of which you use, if you don't include the time, END_DATE should be one day past the last date you want, because a date with no time is one second past midnight minus one second on that date [IOW, just after midnight, but not yet one second past].)
     
    Rukbat, Oct 14, 2011 IP