convert varchar to date format
-
Hello , I want to wirte a sql statment which converts varchar into date (mm/dd/yyyy) format. please help thanks
CAST( @var AS datetime )
works well for dates in the current DATEFORMAT or using ISO 8601 format (yyyyMMdd). TheDATEFORMAT
defaults to the appropriate format for the currentLANGUAGE
(really a locale). The default value forLANGUAGE
comes from the user's login, which in turn gets it (at creation time) from the server'sdefault language
option. Otherwise look atCONVERT
. As a best practice you should pass dates and indeed all other user-supplied data using parameterized queries, for which see the documentation for the provider you're using. That passes the data using a well-understood datatype, rather than parsing the information multiple times.Stability. What an interesting concept. -- Chris Maunder