- (Subtract) (TSQL Operator)

Subtracts two numbers. It also subtracts a number of days from a datetime.

Syntax

expression - expression

datetime - number_of_days

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 subtract from datetime. It is of type int.

Return Types

For arithmetic subtraction, returns the datatype of the expression with the highest type precedence.

For datetime - number_of_days, returns datetime.

Examples

PRINT 123.45 - 30;

-- varchar is converted to int, because int has highest type precedence
PRINT '123' - 50;

The result is:

93.45
73

Example datetime - number_of_days

DECLARE @d DATETIME = '1978-02-01 13:30';
PRINT @d - 5;

The result is:

1978-01-27 13:30:00