Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2012
    Posts
    1

    Unanswered: Select Product based on date

    Hai,




    Product Date
    --------------------------------------------------------
    pd0 2012-08-11 18:45:55.780
    Pd1 2012-08-11 18:55:17.020
    pd2 2012-08-11 19:06:58.623
    pd3 2012-08-18 12:00:01.193
    pd4 2012-08-25 12:13:04.077
    pd5 2012-08-25 17:28:30.347
    pd6 2012-08-25 18:23:16.473
    pd7 2012-09-18 18:29:58.360


    I want select the product based on from date and to date.

    For Example

    I want the select the product date in between 2012-08-11 to 2012-08-18

    Note:dont check the time.

    I want the query for select product based on only date not depend upon time

  2. #2
    Join Date
    Apr 2012
    Posts
    213
    Hi,

    Try:

    Code:
    select * from MyTable
    where MyDate >= '2012-08-11' and 
          MyDate < DATEADD(day, 1, CAST('2012-08-18' as DATE))
    Hope this helps.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    please explain why you use a string '2012-08-11' in one case, but then use CAST on '2012-08-18' in the next case

    why wouldn't you use CAST consistently -- in both cases, or in neither
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Apr 2012
    Posts
    213
    Sorry, it was my fault.

    Code:
    select * from MyTable
    where MyDate >= '2012-08-11' and 
          MyDate < DATEADD(day, 1, '2012-08-18')
    I think it would be better add 1 day in application instead of using the DATEADD function.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by imex View Post
    I think it would be better add 1 day in application instead of using the DATEADD function.
    Why ?
    George
    Home | Blog

  6. #6
    Join Date
    Apr 2012
    Posts
    213
    I believe it would be something easy to do in the application, and in this case would be a function less for SQL Server.

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    wow, like DATEADD(day, 1, '2012-08-18') is really gonna slow things down, eh
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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