SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check if the current date is between two dates

    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.

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code MySQL:
    Select * from tblEvents where event_start >= '2007-06-01' and event_end <= '2007-06-05'
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I think it isn't ok. I have a calendar and when I click a date I must display the events that match that date. It can be done with BETWEEN?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Psyche View Post
    It can be done with BETWEEN?
    it can

    Code:
    select ...
      from ...
     where current_date between event_start and event_end
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! It works.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    who said sql was hard, eh?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •