Check if the current date is between two dates

Discussion in 'Databases' started by cosminc, Jun 2, 2007.

  1. #1
    Hello,

    I have a table with the folowing fields:
    - id (int)
    - event_title (text)
    - event_description (text)
    - event_start (date)
    - event_end (date)

    I would like to know how can I build a query to select the events available between two dates (event_start and event_end).

    For example, if one of the event has "event_start" = 2007-06-01 and "event_end" = 2007-06-05, if I select 2007-06-02 as the current date I would like to see this event.

    Thanks in advance.
     
    cosminc, Jun 2, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    (DATEDIFF(event_start, NOW()) >= 0 AND DATEDIFF(NOW(), event_end) <= 0)
    Code (markup):
     
    krt, Jun 2, 2007 IP
  3. cosminc

    cosminc Peon

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! It works.
     
    cosminc, Jun 2, 2007 IP