October 28, 2011 at 4:17 am
I'm after a way to strip out the date from a smalldatetime column, but still store it as smalldatetime. Using SQL Server 2005 so no Time data type to cast to.
declare @OrigDT as smalldatetime
declare @NewT as smalldatetime
select @OrigDT = '10/28/2011 11:10'
select @NewT --to return '01/01/1900 11:10'
For building a calendar table, must be an easy way to do it...
Thanks.
October 28, 2011 at 4:54 am
select @NewT = dateadd(day, -1 * datediff(day, '01/01/1900', @OrigDT), @OrigDT)
Seems to do it?
October 28, 2011 at 5:15 am
SELECT DATEADD(dd, DATEDIFF(dd, 0, @OrigDT), 0)
--EDIT-- Mis-read your post, the above removes the time from a datetime. Should have been like the below
SELECT DATEADD(dd, 0-DATEDIFF(dd, 0, @OrigDT), @OrigDT)
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply