SQL Server 2008 is not doing what I expected with DateTime
. It doesn\'t let me set DateTime
variables, no matter what date format I use.
Wh
You Should Try This Way :
DECLARE @TEST DATE
SET @TEST = '05/09/2013'
PRINT @TEST
First of all - use single quotes around your date literals!
Second of all, I would strongly recommend always using the ISO-8601 date format - this works regardless of what your locale, regional or language settings are on your SQL Server.
The ISO-8601 format is either:
YYYYMMDD
for dates only (e.g. 20110825
for the 25th of August, 2011)YYYY-MM-DDTHH:MM:SS
for dates and time (e.g. 2011-08-25T14:15:00
for 25th of AUgust, 14:15/2:15pm in the afternoon)You need to enclose the date time value in quotes:
DECLARE @Test AS DATETIME
SET @Test = '2011-02-15'
PRINT @Test
Try using Select instead of Print
DECLARE @Test AS DATETIME
SET @Test = '2011-02-15'
Select @Test