简体   繁体   English

SQL查询DATEDIFF日期时间字段以分钟为单位

[英]SQL Query DATEDIFF date time fields result in minutes

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... 谁能告诉我如何编写SQL查询来计算存储为DATETIME列的2列之间的时间差并以分钟为单位获取结果...

For example: 例如:

Table structure 表结构

ID, start-time, end-time

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. 我想对特定的ID进行选择,并计算结束时间-开始时间,并仅以分钟为单位返回结果。

MySql : TimeStampDiff : 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 Server,则可以使用DATEDIFF

SELECT DATEDIFF(minute, start-time, end-time) FROM tableName where id=1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM