SQLTeam.com | Weblogs | Forums

How to convert a date?


#1

How to convert the date in sql for example, 08/01/2017 to Aug 1, 2017 in sql?


#2

We do that in the APP - i.e. in the "presentation layer". If you do it in SQL you lose the fact that it is a date, so you can't do anything useful (i.e. in a "Date" sense) with it in the APP - unless you convert it back to a date, which has all the usual caveats of being "fragile" in terms of whether the conversion is UNambiguous


#3

SQL provides a "CONVERT" function to do that. In your specific case, you need format code 107, like so:

SELECT CONVERT(varchar(30), CAST('08/01/2017' AS datetime), 107)