Dates and Where clause

  • I'm not sure how to do this. I need:

    (rqst_dlv_date_time >= '07/26/07 00:00:00' 

    AND rqst_dlv_date_time <= '07/28/07 23:59:59'

    OR rqst_dlv_date_time IS NULL)

    I want from the beginning of yesterday until the end of tomorrow but I need it to be dynamic on what ever the current day is.

    If I do rqst_dlv_date_time >= dateadd(day,-1,getdate()) I get yesterday but I need the time portion to be the BEGINNING of yesterday.

    If I do rqst_dlv_date_time <= dateadd(day,1,getdate()) I get tomorrow but I need the time portion to be the END of tomorrow.

  • This should do it (yesterday, tomorrow).

    DATEADD(D, -1, DATEDIFF(D, 0, GetDate()))

    AND

    DATEADD(D, +1, DATEDIFF(D, 0, GetDate()))

  • Works great - thanks so much!

  • BTW, you'll need to use >= AND then < (because the 2nd date is at midnight so you'll want to filter that out).

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply