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 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 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply