SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about "BETWEEN"

    Suppose that value1 and value2 are dates, and that date is a date field in the database. This query:

    Code:
    SELECT *
    FROM table
    WHERE date BETWEEN value1 and value2
    returns all the rows where the date field is between value1 and value2.

    What if I want to return all the rows where the date field goes just from value1 or just to value2? Is this possible using BETWEEN?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Could you give an example of what you mean? The way you've described is kinda vague tbh.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I though so

    I mean, I want to find all the rows that have a date that goes from "March 13th 2011" on, with no upper limit.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The normal comparison operators work on dates to in MySQL, so you can just use

    WHERE date > value

    or WHERE date >= value if you want to include value itself
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    The normal comparison operators work on dates to in MySQL, so you can just use

    WHERE date > value

    or WHERE date >= value if you want to include value itself
    Awesome, thank you very much!


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
  •