问题
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