+ (Add) (TSQL Operator)
Adds two numbers. It also adds a number of days to a datetime, or a time to a date.
Syntax
expression + expression
datetime + number_of_days
date + time
Arguments
- expression
- is a numeric expression of type
tinyint
,smallint
,int
,bigint
,money
,numeric
,float
. - datetime
- is an expression of type
datetime
. - number_of_days
- is the number of days to add to datetime. It is of type
int
. - date
- is an expression of type
date
. - time
- is an expression of type
time
, to add to date.
Return Types
For arithmetic addition, returns the datatype of the expression with the highest type precedence.
For datetime + number_of_days
and date + time
, returns datetime
.
Remarks
MS SQL Server doesn’t allow
date + time
.
Examples
PRINT 123.45 + 1000;
-- varchar is converted to int, because int has highest type precedence
PRINT '123' + 50;
The result is:
1123.45
173
Example datetime + number_of_days
DECLARE @d DATETIME = '1978-02-01 13:30';
PRINT @d + 5;
The result is:
1978-02-06 13:30:00
Example date + time
DECLARE @d DATE = '1978-02-01 13:30';
DECLARE @t TIME = '13:30';
PRINT @d + @t;
The result is:
1978-02-01 13:30:00