SQL Query DATEDIFF date time fields result in minutes

无人久伴 提交于 2019-12-12 06:38:42

问题


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...

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.


回答1:


MySql : TimeStampDiff:

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

SqlServer: DATEDIFF

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



回答2:


If you're using SQL Server, you can use DATEDIFF

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


来源:https://stackoverflow.com/questions/22164002/sql-query-datediff-date-time-fields-result-in-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!