In the following SQL statement there's some T-SQL that adds a number to a datetime
and to a date
:
declare @t table(UserID int, StartDate datetime, EndDate date)
insert @t select 1, '20110101', '20110102'
-- Adding int to a datetime works
select t.StartDate + 2 as NewStartDate
-- Adding int to a date errors
select t.EndDate + 2 as NewEndDate
I would expect both of the above select statements to fail because neither are using the DATEADD
method, but to my surprise adding an int
to a datetime
without using DATEADD
works. Why is that?