user3312251
user3312251

Reputation: 25

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

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.

Upvotes: 0

Views: 2956

Answers (2)

Nagaraj S
Nagaraj S

Reputation: 13474

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

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

Upvotes: 0

StuartLC
StuartLC

Reputation: 107237

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;

Upvotes: 1

Related Questions