两次中间的时间 [英] middle time between two time

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

问题描述

如果我有StartTime = 12:00:00 PM

和EndTime = 6:00:00 PM



现在我需要时间介于这两个时间之间,意味着我需要3:00:00 PM



如何在存储过程中执行此操作。

if i have StartTime=12:00:00 PM
and EndTime=6:00:00 PM

now i need Time Between this two time ,means i need 3:00:00 PM

how to do this in stored procedure.

推荐答案

公式很简单。你添加两个数字并将它们除以2并得到中间值。

但问题是这里的数字是时间格式。此外,可能存在AM / PM问题。

这就是你在这里做的:

The formula is simple. You add the two numbers and divide them by 2 and you have the mid value.
But the problem here is the numbers here are in time format. Moreover there could be AM/PM issues.
So this is what you do here:
STEP 1: Convert Time1 to milliseconds
STEP 2: Convert Time2 to milliseconds
STEP 3: Result_In_MilliSeconds = (Result_From_Step1 + Result_From_Step2) / 2 
STEP 4: Convert Result_In_MilliSeconds into required time format.





我将留下语法部分供您使用。 Google提供了有关如何进行这些转换的帮助。



I will leave syntax part for you to do. There is help on Google on how you do these conversions.


这是查询。



SELECT DATEADD(ms,DATEDIFF(ms,''2012-10-04 12:48:56:000'',''2012-10-04 12 :48:58:000'')/ 2,''2012-10-04 12:48:56:000'')
This is the query .

SELECT DATEADD(ms,DATEDIFF(ms,''2012-10-04 12:48:56:000'', ''2012-10-04 12:48:58:000'')/2,''2012-10-04 12:48:56:000'')


了解 TimeSpan 。您需要找到注销时间和登录时间之间的差异。使用Timespan,您可以获得小时/分钟/秒等的差异



步骤:

1.获取时间跨度( ts)来自& 约会。

2.将 ts 的一半加到 日期或减去 ts <的一半日期。



参考:

MSDN:TimeSpan结构 [ ^ ]

DateTime.Subtract Method(TimeSpan) [ ^ ]



以上解决方案是关于服务器端代码。数据库查询的逻辑也一样。将其转换为标准格式,然后得到差异,然后将差异的一半加到初始日期。
Read about TimeSpan. You need to find the difference between the logout time and the login time. Using Timespan, you get the difference in terms of hours/minutes/seconds, etc

Steps here:
1. Get the timespan(ts) between from & to date.
2. Add half of ts to from date OR substract half of ts from to date.

Refer:
MSDN: TimeSpan Structure[^]
DateTime.Subtract Method (TimeSpan)[^]

Above solution is to do on server side code. Logic remains same for database query too. Convert it into a standard format and then get the difference and then add half the difference to initial date.


这篇关于两次中间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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