SQL SERVER – Puzzle – Adding Two Dates Resulting Strange Results

This puzzle, I have discovered accidentally. In one of the recent project, I had to display two dates next to each other. Now, when I was doing this, I accidentally did a mistake while I was typing that out. Indeed, this puzzle about strange results when adding two dates.

SQL SERVER - Puzzle - Adding Two Dates Resulting Strange Results puzzledatedate-800x398

What I actually wanted to do was-

SELECT @date1, @date2

However, when I ended up typing was

SELECT @date1+@date2

Now I think it is very strange as the comma and the plus signs are nowhere near on a typewriter and I had ended up making this mistake.

The good thing is that I ended up learning something new which helped me build this puzzle.

Puzzle:

Let us execute the following code

DECLARE @date1 DATETIME, @date2 DATETIME
SELECT @date1='2010-01-20', @date2='2016-10-22'
SELECT @date1+@date2 AS result 

When I executed above code I ended up with the following result-

SQL SERVER - Puzzle - Adding Two Dates Resulting Strange Results datetimepuzzle

Now my question is how come we see the result as some date in the year 2126 and not an error?

Let me know what is your answer in the comments section. I will keep all the answers hidden till Monday.

If you like such puzzles, here are three puzzles which I had published in the recent time-

Reference: Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

SQL DateTime, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Puzzle – Shortest Code to Produce the Number 1000000000 (One Billion)
Next Post
SQL SERVER – Puzzle – Brain Teaser – Changing Data Type is Changing the Default Value

Related Posts

Leave a Reply