Wednesday, June 6, 2012

t-sql display date, time, time period

Quick post on how to display date, time, and time period in T-SQL:

SELECT
GETDATE() AS this_date_time
, CONVERT(VARCHAR, GETDATE(), 101) AS this_date
, RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) AS this_time
, ( CONVERT(VARCHAR, GETDATE(), 101) + ' ' + RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) ) AS this_date_time