How Can I use “Date” Datatype in sql server?

You do not have a problem with the “last two”.

However, you do have a problem with all of them, but one point after the other.

Literal dates are dependent on your system’s culture

Your dates are interpreted as MM-DD-YYYY. This intrepretation is depenent on your system’s culture. The first three are turning into wrong dates but work. The 4th breaks and the fifth is never executed (due to the error before).

So the actual error lies on line 4.

Whenever you deal with dates, use culture independent formats. It is better to use either of the following-

universal format

20150730 (=> the 30th of July in 2015)

ODBC-format

{d'2015-07-30'} or {t'23:30:59'} or {ts'2015-07-30 23:30:59'}

ISO 8601

'2015-07-30T00:00:00'

Leave a Comment