Monday, 15 August 2011

sql server 2008 - Subtract two dates in sql to hhhh:mm:ss -



sql server 2008 - Subtract two dates in sql to hhhh:mm:ss -

i want subtract 2 dates , hhhh:mm:ss when number of hours may greater 24

and not want limit number of hours hhhh. have 2 dates, date1='1900-01-01 00:00:00.000' , date2='1900-01-02 01:00:00.000'. want get:

date2-date1 = '25:00:00.0'

you can create in character info type because range of info type time 00:00:00.0000000 through 23:59:59.9999999

declare @date1 datetime = '19000101 00:00:00.000', @date2 datetime = '19000102 01:00:00.000' select cast(datediff(hour, @date1, @date2) nvarchar(5))+ ':00:00.0'

demo on sqlfiddle

sql sql-server-2008

No comments:

Post a Comment