从两个日期的datediff获取时间值 [英] Get time value from datediff of two dates
问题描述
我想从sql server 2008中两个日期的datediff中获取时间数据类型的值.
Hi,
I want a value of time data type from datediff of two dates in sql server 2008.
推荐答案
请使用
datepart paramter in DATEDIFF ( datepart , startdate , enddate )
datepart
是startdate和enddate的一部分,用于指定跨越边界的类型.下表列出了所有有效的datepart参数.用户定义的变量等效项无效.
http://msdn.microsoft.com/en-us/library/ms189794.aspx [ ^ ]
Is the part of startdate and enddate that specifies the type of boundary crossed. The following table lists all valid datepart arguments. User-defined variable equivalents are not valid.
http://msdn.microsoft.com/en-us/library/ms189794.aspx[^]
DateTime startdts = new DateTime(29, 3, 2012, 14, 0, 0);
TimeSpan span = DateTime.Now - startdts;
然后可以使用span.Total ......获取两个DateTime对象的总时间差.
希望这会有所帮助.
Then you can use span.Total...... to get the total time difference of the two DateTime objects.
Hope this helps.
TimeSpan diff = DateTime.Now.AddHours(2) - DateTime.Now;
TimeSpan具有时间,小时,分钟,秒等属性.您还需要什么?
TimeSpan has properties for time, hours, minutes, seconds, etc. What more do you need?
这篇关于从两个日期的datediff获取时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!