Thread: SQL Question

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    SQL Question


    Hi All,
    I'm newbie in SQL thing and would like to ask a question on how to select right data in date range.
    I know on how to select data within some date range with help of "BETWEEN" but it doesn't work for me.
    Imagine i have a table:
    ID, NAME, DATE

    and then i have data in there:
    1, asd, 2010-11-11 15:00:34
    2, asd, 2010-11-12 16:00:34
    3, asd, 2010-11-13 17:00:34
    4, asd, 2010-11-14 18:00:34
    5, asd, 2010-11-15 19:00:34
    6, asd, 2010-11-16 20:00:34
    7, asd, 2010-11-17 11:00:34
    8, asd, 2010-11-18 12:00:34
    9, asd, 2010-11-19 19:00:34
    10, asd, 2010-11-20 14:00:34
    11, asd, 2010-11-21 18:00:34

    i need to select data from this table where TIME ( ONLY TIME ) is between 18:00:00 and 20:00:00
    So result of this query should be:

    4, asd, 2010-11-14 18:00:34
    5, asd, 2010-11-15 19:00:34
    6, asd, 2010-11-16 20:00:34
    9, asd, 2010-11-19 19:00:34
    11, asd, 2010-11-21 18:00:34

    Have no idea how to archive this

    Can anybody help me please?
    Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,382
    Rep Power
    391
    Code:
    select <columnsOfInterest>
      from t
     where cast("DATE" as time) between time '18:00:00' and time'20:00:00'
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0
    Wow, thank you

IMN logo majestic logo threadwatch logo seochat tools logo