Getdate pulls time from midnight to 23:59 hours

  • Hi SQL experts - What is the proper way to ensure when pulling date between two getdates, that you include from midnight of the first getdate to 23:59 hours in the second getdate?

    WD.WRKD_WORK_DATE

    and WD.WRKD_WORK_DATE between DATEADD(DD, - 11, GETDATE())

    and DATEADD(DD, - 5, GETDATE())

    Sandy Tucker

  • SandyTucker (6/23/2015)


    Hi SQL experts - What is the proper way to ensure when pulling date between two getdates, that you include from midnight of the first getdate to 23:59 hours in the second getdate?

    This is one way:

    WHERE (WD.WRKD_WORK_DATE >= cast(DATEADD(DD, - 11, GETDATE()) as date)

    and WD.WRKD_WORK_DATE < cast(DATEADD(DD, -4, GETDATE()) as date))

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Hello LinksUp - thanks very much, that seems to be working well!

    Sandy Tucker

  • Glad it worked for you!

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/

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

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