使用 t-sql 计算时间跨度 [英] Calculating timespan with t-sql
本文介绍了使用 t-sql 计算时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定两个日期/时间:
@start_date = '2009-04-15 10:24:00.000'
@end_date = '2009-04-16 19:43:01.000'
是否可以按以下格式计算两个日期之间经过的时间
Is it possible to calculate the time elapsed between the two dates in the following format
1d 9h 19m
推荐答案
您可以将两个日期之间的差异设为您想要的任何分辨率(在您的示例中为分钟):
You can get the difference between the two dates to whatever resolution you want (in your example, minutes):
DATEDIFF(minute, @start_date, @end_date)
从那里开始,只需将分钟划分为小时,将小时划分为几天,然后修改其余部分.
From there it's a simple matter of dividing minutes into hours and hours into days and modding the remainder.
这篇关于使用 t-sql 计算时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文