How to Calculate Total Minutes in SQL
Database developers are often asked to create reports using complex queries. When developing reports using queries in SQL Server Management Studio, you may need to display the total time passed between two dates. Display how many years, months, weeks, hours and minutes have passed between two dates by using Microsoft SQL Server's DATEDIFF() formula.
Instructions
-
-
1
Open SQL Server Management Studio and log in to the SQL Server instance you would like to use.
-
2
Open a new query editor window by clicking on the "New Query" button on the Standard toolbar.
-
-
3
Use the following code and replace database, table and column names with appropriate fields that match your database:
USE DatabaseName;
GO
SELECT DATEDIFF(mi, 'StartDate', 'EndDate') AS TotalMinutes;
-
4
Highlight the query and click the "Execute" button on the SQL Editor toolbar.
-
1
References
- Photo Credit Thinkstock Images/Comstock/Getty Images