Results 1 to 3 of 3

Thread: Date Range

  1. #1
    Join Date
    Jun 2011
    Posts
    6

    Unanswered: Date Range

    Dear All,

    I need to reterview data between the time range ie.Yesterday 1 Am to today 1 Am record (24hrs)

    The below query pulls the data between (2011-07-04 00:00:00.000 to
    2011-07-04 23:59:59.999)

    cst.DateCreated >=DATEADD(dd,DATEDIFF(dd,0,GETDATE())-1,0)
    AND cs.DateCreated <DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)

    But i need data from (2011-07-04 01:00:00.000 to
    2011-07-05 00:59:59.999).How to amend that query.Any Help would be highly appreciated.

    Regards,
    SG

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Try:
    Code:
    cst.DateCreated >= DATEADD(hh, 1, DATEADD(dd,DATEDIFF(dd,0,GETDATE())-1,0))
    AND cs.DateCreated < DATEADD(hh, 1, DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0))
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Code:
    cst.DateCreated >= dateadd(hour,1,cast(CAST(getdate()-1 as date) as datetime)) and
    cst.DateCreated < dateadd(hour,1,cast(CAST(getdate() as date) as datetime))
    This time I was a bit late Wim, but we still think the same
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

Tags for this Thread

Posting Permissions

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