Not logged in - Login

Simple Date Conversions in SQL

Some simple date conversions in SQL

declare @dtShortDate date 
       , @dtShortTime datetime
       , @dtFullDateTime datetime
set @dtFullDateTime = getdate() -- get the current date & time
set @dtShortDate = @dtFullDateTime -- strips off the time portion


set @dtShortTime = '1900-01-01' -- set the short time field to have a date of 1-1-1900
-- add the time portion to the short date field
set @dtShortTime = DATEADD(ms, datediff(ms, @dtShortDate, @dtFullDateTime), @dtShortTime)


print convert(varchar, @dtfulldatetime, 121)
print @dtShortDate
print convert(varchar, @dtShortTime, 121)