Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Literal DateTime for SqlServer (See related posts)

   1  
   2  CONVERT(DATETIME, 'yyyymmdd', 112)

112 -> ISO date
cf. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp
----------
Edit: a better solution !
   1  
   2  {d 'yyyy-mm-dd'}

Thanks to Wild Richard (http://www.bigbold.com/snippets/posts/show/756)

Comments on this post

Will_Rickards posts on Sep 20, 2005 at 16:12
I prefer to use odbc canonical
dates
{d 'yyyy-mm-dd'}

times
{t 'hh:mm:ss'}

timestamps
{ts 'yyyy-mm-dd hh:mm:ss'}

See MS reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetdate_time_and_timestamp_literals.asp

It is a pity that there isn't some sort of SQL standard for date representation. Or maybe there is and I don't know it?
ms_michel posts on Sep 20, 2005 at 16:22
I believed {d 'yyyy-mm-dd'} works only for ODBC. And I never thought to check it !
Will_Rickards posts on Sep 20, 2005 at 19:38
Yes it works in query analyzer, via ado (oledb or odbc providers), via ado.net (sqlclient or odbc).
Will_Rickards posts on Sep 20, 2005 at 19:43
And in stored procedures (just verified with Sql server 7)

You need to create an account or log in to post comments to this site.


Click here to browse all 5309 code snippets

Related Posts