SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to query by date?

    Hi!

    I want to find if a record in the database has overlapping date range as compared to a date range I have on hand.

    For example:

    If the database has a record with a startDateTime of 2011-05-19 10:00:00 and endDateTime of 2011-05-19 11:00:00.

    If I have a date range of startDateTime of 2011-05-19 09:30:00 and endDateTime of 2011-05-19 10:30:00.

    or my date range is startDateTIme 2011-05-19 10:30:00 and endDateTime of 2011-05-19 11:30:00.

    How can I search the database in such a way that I do not get any records if the date/time do not overlap with the date/time I have on hand.

    Many thanks.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    WHERE table.startDateTime < '$endDateTime'
    AND   table.endDateTime   > '$startDateTime'


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
  •