Results 1 to 3 of 3

Thread: date between

  1. #1
    Join Date
    Oct 2002
    Posts
    3

    Unanswered: date between

    hi, anybody know an easy way to select fields between two dates? I have tried dateadd like DATEADD(day, 28, myDate) but the result I want is from i.e 07.15 to 08.15.

    I have also tried something like CONVERT(varchar, myDate, 104) BETWEEN '07.15.2002' AND '08.15.2002'

    anyone have another suggestion?

  2. #2
    Join Date
    Oct 2002
    Posts
    369

    Question Re: date between

    Originally posted by catorene RE: hi, anybody know an easy way to select fields between two dates? I have tried dateadd like DATEADD(day, 28, myDate) but the result I want is from i.e 07.15 to 08.15. I have also tried something like CONVERT(varchar, myDate, 104) BETWEEN '07.15.2002' AND '08.15.2002'
    anyone have another suggestion?
    Q1 [Anybody know an (easy?) way to select fields between two dates?]
    A1 It isn't really clear what you are asking about. A between syntax example?:

    SELECT ord_date AS DatesBetween19930221And19940913
    FROM pubs.dbo.sales
    WHERE (ord_date Between CONVERT(DATETIME, '1993-02-21 00:00:00', 102) AND CONVERT(DATETIME, '1994-09-13 00:00:00', 102))
    ORDER BY ord_date

    SELECT ord_date AS DatesBetween19930221And19940913
    FROM pubs.dbo.sales
    WHERE (ord_date > CONVERT(DATETIME, '1993-02-21 00:00:00', 102)) AND (ord_date < CONVERT(DATETIME, '1994-09-13 00:00:00', 102))
    ORDER BY ord_date

  3. #3
    Join Date
    Feb 2002
    Posts
    2,232
    You actually were on the right track - it is just that style 104 is the format dd.mm.yy not mm.dd.yy like in your between clause. So if you modified your dates in the between clause to be 15.07.2002 and 15.08.2002 you would be ok. Also, you could use style 101 but you would need slashes instead of periods - and your date 07/15/2002 and 08/15/2002 would work as well.

Posting Permissions

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