SQL查询DATEDIFF日期时间字段以分钟为单位 [英] SQL Query DATEDIFF date time fields result in minutes

查看:382
本文介绍了SQL查询DATEDIFF日期时间字段以分钟为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何编写SQL查询来计算存储为 DATETIME 列的2列之间的时间差,并在几分钟内得到结果...

Can anyone tell me how to write the SQL Query to calculate the time difference between 2 columns that are stored as DATETIME columns and get the result in minutes...

例如:

表结构

ID, start-time, end-time

我想做选择一个特定的ID并计算结束时间-开始时间,并仅以分钟为单位返回结果。

I want to do a select on a specific ID and perform a calculation of the end-time - start-time and return the result in minutes only.

推荐答案

MySql: TimeStampDiff

SELECT TIMESTAMPDIFF(MINUTE, start_time, end_time)
FROM MyTable
WHERE ID = 1;

SqlServer: DATEDIFF

SqlServer: DATEDIFF

SELECT DATEDIFF(n, start_time, end_time)
FROM MyTable
WHERE ID = 1;

这篇关于SQL查询DATEDIFF日期时间字段以分钟为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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