Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get date with specific hour

Author  Topic 

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2014-07-08 : 03:19:07
Hi
from getdate(), how can i get today's date with specific time :

For example : (i just need specific 11oclock today)
2014-07-08 11:00:00.000

This do the trick :
select DATEADD( HH, 11, CAST(CAST(DATEADD(DAY,-1,GETDATE()) AS INT) AS DATETIME))

But at second half of the day it changed from 2014-07-08 11:00:00.000 to the next day, i dont know why


~~~who controls the past controls the future, who controls the present controls the past. ¯\(º_o)/¯ ~~~

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-07-08 : 04:41:31
try this:

select
getdate() as [Getdate],

dateadd(day,datediff(day,0,getdate()),0) as [Date 00:00],

dateadd(hour,11,
dateadd(day,datediff(day,0,getdate()),0)
) as [Date with specific hour]



Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -