Chis Chis - 1 year ago 126
SQL Question

Convert from VARCHAR to DATETIME

I need to convert all values in a table and I need that change to be permanent so the table has dates and they are formatted like

I need to change them to
Format which is

Answer Source

If your dates are stored with the appropriate data type (date, datetime or datetime2), then they are stored without any display format.

If that is the case you need to convert them to char(10) when selecting the data:

SELECT CONVERT(char(10), DateTimeColumn, 120)

If they are stored as a string type, you should refactor your database and store them properly. If that's impossible for some reason, you can convert twice. one from string to date, and the other one back to string:

SELECT CONVERT(char(10), CONVERT(date, DateTimeStringColumn, 104), 120)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download