SQL中的日,小时,分钟格式 [英] Day, Hours, Min format in SQL

查看:88
本文介绍了SQL中的日,小时,分钟格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我创建了一个显示部件,其中显示了一些细节,例如
录入日期,
验证日期,
名称

我想显示一个col.作为TAT(日期和时间格式)
TAT =输入日期和验证日期之间的差异
例如:1d 6h 33m

我想使用SQL显示此内容.请给我任何建议.

Dear Friends,

I have created a display part, which displays few details such as
Entry Date,
Verified date,
Name

I want to display a col. as TAT(Date and time format)
TAT=Difference between Entry Date and Verified date
Eg: 1d 6h 33m

This I want to display using SQL. Kindly provide me any suggestion.

推荐答案

阅读::http://social.msdn.microsoft.com/Forums/en/transactsql/thread/5e5a4474-31b8-4316-8a34-1e4a5572fb49 [ ^ ]


通常,所有格式化都应在客户端完成,而不要使用数据库.

但是,您可以使用DATEDIFF函数来计算到日期之间的差异,并根据要求对其进行格式化.有关语法,请参见 DATEDIFF [
Typically all the formatting should be done on the client side, not using the database.

However, you can use the DATEDIFF function to calculate the difference between to dates and format it as per requirements. For the syntax, see DATEDIFF[^]


Select convert(varchar,Datepart(d,TAT))+'d '+convert(varchar,Datepart(hh,TAT))+'h '+convert(varchar,Datepart(m,TAT))+'m'
from tablename


这篇关于SQL中的日,小时,分钟格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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