Collections:
Subtracting a DATETIME Value from Another DATETIME Value in SQL Server
Can a DATETIME Value Be Subtracted from Another DATETIME Value in SQL Server Transact-SQL?
✍: FYIcenter.com
Can a datetime value be subtracted from another datetime value? The answer is yes. The subtract operation can be performed by the subtract operator (-) as:
The tutorial exercise below shows you some good examples:
DECLARE @birth_date DATETIME; DECLARE @today_date DATETIME; SET @birth_date = '2000-02-29 16:00:00.000'; SET @today_date = '2007-05-19 22:00:00.000'; SELECT @today_date - @birth_date; GO 1907-03-22 06:00:00.000 DECLARE @birth_date DATETIME; DECLARE @today_date DATETIME; DECLARE @age NUMERIC(9,2); SET @birth_date = '2000-02-29 16:00:00.000'; SET @today_date = '2007-05-19 22:00:00.000'; SET @age = CONVERT(NUMERIC(9,2), @today_date - @birth_date); SELECT @age; GO 2636.25
⇒ Date and Time Functions Supported by SQL Server 2005 in SQL Server
⇐ Converting DATETIME and NUMERIC Values in SQL Server
⇑ Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-20, 2110🔥, 0💬
Popular Posts:
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
How REAL and FLOAT Literal Values Are Rounded in SQL Server Transact-SQL? By definition, FLOAT(n) sh...
How To Count Rows with the COUNT(*) Function in SQL Server? If you want to count the number of rows,...
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...