如何减去access sql查询中的时间两列
我在其中一张表中有两列:Arrival_Time
和Leaving_Time
。 两者都是时间字段,格式如下:HH:MM:SS
。
我想从 Arrival_Time
中减去 Leaving_Time
,例如:
到达时间:02:00:00
出发时间:02:45:00 = 45 分钟。
我尝试了这个查询:
SELECT (Jobs.Leaving_time) - (Jobs.Arrival_Time) AS Time_Difference
FROM Technicians,Jobs, Tech_Allocation
WHERE Jobs.Job_ID=Tech_Allocation.Job_ID
AND Tech_Allocation.Technician_ID=Technicians.Technician_ID
ORDER BY (Jobs.Leaving_time) - (Jobs.Arrival_Time) ASC;
查询运行,但减法的结果以小数形式显示,而不是我希望的分钟数。
谢谢
I have two columns in one of the tables : Arrival_Time
and Leaving_Time
.
Both are time fields which are formatted like this: HH:MM:SS
.
I want to subtract Leaving_Time
from Arrival_Time
, for example:
Arrival time: 02:00:00
Leaving_time: 02:45:00 = 45 minutes.
I tried this query :
SELECT (Jobs.Leaving_time) - (Jobs.Arrival_Time) AS Time_Difference
FROM Technicians,Jobs, Tech_Allocation
WHERE Jobs.Job_ID=Tech_Allocation.Job_ID
AND Tech_Allocation.Technician_ID=Technicians.Technician_ID
ORDER BY (Jobs.Leaving_time) - (Jobs.Arrival_Time) ASC;
The query runs but the results of the subtraction are shown in decimals not as minutes as I want them to be.
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的问题中,您说您希望持续时间显示为分钟。然而,在评论中,您说您希望结果显示为小时:分钟:秒。
使用 Format() 函数将浮点值显示为小时:分钟:秒。
请注意,此方法仅对小于 24 小时的 Time_Differences 有效。
编辑:
In your question, you said you want the time duration displayed as minutes. However in a comment, you said you want the result displayed as Hour:Minutes:Seconds.
Use the Format() function to display your float value as Hour:Minutes:Seconds.
Beware, this approach is only valid for Time_Differences less than 24 hours.
Edit:
由于您使用的是 MS Access,我发现此 MS Office 讨论标题为 准时以及已经过去了多少。请看一下
totalminutes = Int(CSng(interval * 1440))
之类的内容是否有意义。Since you're using MS Access, I found this MS Office discussion entitled On time and how much has elapsed. Please take a look and see if things like
totalminutes = Int(CSng(interval * 1440))
make sense.在 Access 中,您需要查看 DateDiff( )函数。
In Access, you'll want to look at the DateDiff() function.