The correct answer has already given "usage parameters". Formatting the date and passing it as a string to SQL-Server can lead to errors, because it depends on the settings of how the date is interpreted on the server side. In Europe, we write "December 1, 2012" to indicate December 1, 2012, while in other countries this can be considered as January 12.
When issuing statements directly to SSMS, I use the yyyymmdd format, which looks pretty general. I did not encounter any problems on the various installations that I have worked on so far.
There is another rarely used format that is a bit strange, but works for all versions:
select { d '2013-10-01' }
will return the first of October 2013.
select { ts '2013-10-01 13:45:01' }
will return on October 1, 1:45:01
I highly recommend using parameters and never formatting your own SQL code by inserting home-made formatted report fragments together. This entry is for SQL injection and weird errors (formatting the float value is another potential problem)
alzaimar Jul 02 '13 at 6:34 2013-07-02 06:34
source share