Tuesday, October 06, 2009

SQL Server Time Formats, SQL Server Time Format Examples


SELECT cast(datediff(mi,'11:00 AM','7:10 PM')/60 as varchar(10))+':'+cast(datediff(mi,'11:00 AM','7:10 PM')%60 as varchar(10))+':00'

SELECT CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinute

SELECT convert(varchar(10),getdate(),114)

SELECT right(CONVERT( varchar, getDate(), 100),7)

SELECT RIGHT('0'+LTRIM(RIGHT(CONVERT(varchar,getDate(),100),8)),7)

SELECT REPLACE(REPLACE(RIGHT('0'+LTRIM(RIGHT(CONVERT(varchar,getDate(),100),7)),7),'AM',' AM'),'PM',' PM')

SELECT RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100),7)

SELECT stuff( right( convert( varchar(26), getDate(), 109 ), 15 ), 7, 7, ' ' )

SELECT RIGHT('0'+LTRIM(RIGHT(CONVERT(varchar,getDate(),100),8)),7)

SELECT substring(convert(varchar(20), GetDate(), 9), 13, 5)

+ ' ' + substring(convert(varchar(30), GetDate(), 9), 25, 2)

SELECT

GETDATE() AS CurrentDate,

RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) AS CurrentTime,

CONVERT(VARCHAR(10), GETDATE(), 101) + ' ' + RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) AS CurrentDateTime

No comments: