Set time portion of a datetime variable

后端 未结 6 1036
慢半拍i
慢半拍i 2020-12-09 18:25

I am working on a query that will be an automated job. It needs to find all the transactions between 8 PM and 8 PM for the last day. I was thinking of doing something like

6条回答
  •  春和景丽
    2020-12-09 19:16

    I needed to pull a date from the database and append 3:00 Pm to it. I did it this way

    select dateadd(hour, 15, datediff(day, 0, myDatabaseDate)) 
    from dbo.myDatabaseTable
    where myDatabaseId = 1
    

    The result that it returned was 2017-10-01 15:00:00.000. The date in the database is 2017-10-01. The solution that I proposed was to keep my current date. I added 0 days to my existing date. I gave it 15:00 hours and it worked like a charm.

提交回复
热议问题