MySQL simple question on dates

Discussion in 'Web Design and Development' started by carlosbutler, Mar 31, 2009.

  1. carlosbutler macrumors 6502a

    carlosbutler

    Joined:
    Feb 24, 2008
    Location:
    London City
    #1
    Is it possible to be able to have an SQL query that is able to search through dates with +/- a few days?

    For example if looking for a record with a date on 2009-04-01, could it be expanded to have a range from 2009-03-30 -> 2009-04-03?

    I can guess you are able to do something like:

    select * from 'something' where date < '2009-04-03' and date > '2009-03-30';

    But I am not sure how to get it so that it adds/decreases the dates for the search statement

    Thanks
     
  2. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #2
    Not automatically, but if you don't want to calculate the days:

    Code:
    WHERE <column> BETWEEN DATE_SUB('2009-04-01', INTERVAL 3 DAY) AND DATE_ADD('2009-04-01', INTERVAL 3 DAY)
    
     
  3. carlosbutler thread starter macrumors 6502a

    carlosbutler

    Joined:
    Feb 24, 2008
    Location:
    London City

Share This Page