0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

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;
StuartLC
  • 104,537
  • 17
  • 209
  • 285
0

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

SELECT DATEDIFF(minute, start-time, end-time) FROM tableName where id=1;
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53