在 sql server 2005 中将秒转换为分钟和秒的有效方法 [英] Efficient way to convert second to minute and seconds in sql server 2005

查看:60
本文介绍了在 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

这篇关于在 sql server 2005 中将秒转换为分钟和秒的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆