Skip to content
Advertisement

How to convert “3 Days 18 Hours 39 Minutes” into seconds in SQL Server?

How to convert “3 Days 18 Hours 39 Minutes” into seconds in SQL Server?

Advertisement

Answer

DECLARE @formula varchar(1000)
set @formula = 'select ' + replace(replace(replace('2h 2m', ' ', '+'),'h','*60*60'),'m','*60')
execute(@formula)

Here is a more generic formula you can use. It is fairly error prone though

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement