如何显示回合时间 [英] How to display roundof time

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

问题描述

使用 SQL Server 2005

Using SQL Server 2005

表1

ID Intime Outtime

001 00.21.00 00.48.00
002 08.23.00 13.45.00
003 00.34.00 00.18.00

我需要显示像 30 分钟或 1 小时这样的时间时间,它应该显示一个舍入时间

I need to display the time time like 30 minutes or 1 Hours, it should display a roundoff time

预期输出

ID Intime Outtime

001 00.30.00 01.00.00
002 08.30.00 14.00.00
003 01.00.00 00.30.00

如何查询四舍五入时间.

How to make a query for the roundoff time.

推荐答案

您可以将当前日期四舍五入到 30 分钟,例如:

You can round the current date to 30 minutes like:

select dateadd(mi, datediff(mi,0,getdate())/30*30, 0)

说明:这需要从 0 日期开始的分钟数:

Explanation: this takes the number of minutes since the 0-date:

datediff(mi,0,getdate())

然后通过除以并乘以 30 将其四舍五入为 30 的倍数:

Then it rounds that to a multiple of 30 by dividing and multiplying by 30:

datediff(mi,0,getdate())/30*30

结果加回0-date,找到最近30分钟的区块

The result is added back to the 0-date to find the last 30 minute block

dateadd(mi, datediff(mi,0,getdate())/30*30, 0)

这可以轻松调整 60 分钟.:)

This can be adjusted easily for 60 minutes. :)

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

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