Suppose I have 90 seconds. If I want to display the result in terms of minutes and second, I do it by using
select Time= '0' + CAST( 90/60 as varchar(2)) + ':' + CAST( 90%60 as varchar(2))
The output is
Time
01:30
I have appended 0(zero) because if you do a select getdate()
the output will be
yyyy-mm-dd hh:mm:ss:ms
What is the standard way and recommended practice to do such a conversion?
Thanks
SELECT SEC_TO_TIME( seconds ); SELECT SEC_TO_TIME( seconds ); In this query, the “seconds” parameter is the number of seconds to convert. The result will be displayed in “HH:MM:SS” format.
With hours:
SELECT CONVERT(CHAR(8),DATEADD(second,90,0),108)
00:01:30
Ignoring hours:
SELECT RIGHT(CONVERT(CHAR(8),DATEADD(second,90,0),108),5)
01:30
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With