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.
Author |
Topic |
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2010-07-07 : 07:20:52
|
Hi Folks,I have some questionI need to convert datetime to date hourlike 2010-07-07 15:39:23.967 into 2010-07-07 15:00:00.000.Is there any way in Sql server to convert?RegardsJs.Reddy |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-07-07 : 07:26:17
|
[code]DECLARE @Sample DATETIMESET @Sample = '2010-07-07 15:39:23.967'-- Version 1SELECT @Sample = CONVERT(CHAR(13), @Sample, 121) + ':00'SELECT @Sample AS [Version 1]-- Version 2 (preferred)SELECT @Sample = DATEADD(HOUR, DATEDIFF(HOUR, 0, @Sample), 0)SELECT @Sample AS [Preferred][/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2010-07-07 : 07:33:22
|
Thanks Peso quote: Originally posted by Peso
DECLARE @Sample DATETIMESET @Sample = '2010-07-07 15:39:23.967'-- Version 1SELECT @Sample = CONVERT(CHAR(13), @Sample, 121) + ':00'SELECT @Sample AS [Version 1]-- Version 2 (preferred)SELECT @Sample = DATEADD(HOUR, DATEDIFF(HOUR, 0, @Sample), 0)SELECT @Sample AS [Preferred] N 56°04'39.26"E 12°55'05.63"
|
 |
|
|
|
|