在 sql server 2005 中将秒转换为分钟和秒的有效方法

问题描述:

假设我有 90 秒.如果我想以分钟和秒为单位显示结果,我可以使用

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)) 

输出是

时间
01:30

Time
01:30

我附加了 0(零),因为如果您执行 select getdate() 输出将是

I have appended 0(zero) because if you do a select getdate() the output will be

yyyy-mm-dd hh:mm:ss:ms

yyyy-mm-dd hh:mm:ss:ms

进行此类转换的标准方法和推荐做法是什么?

What is the standard way and recommended practice to do such a conversion?

谢谢

带小时:

SELECT CONVERT(CHAR(8),DATEADD(second,90,0),108)
00:01:30

忽略时间:

SELECT RIGHT(CONVERT(CHAR(8),DATEADD(second,90,0),108),5)
01:30