I'm trying to convert a date in a varchar
column in the dd/mm/yyyy
format into the datetime dd/mm/yyyy
format, so then I can run date range queries on the data.
So far I have the following which is not working
CONVERT(varchar, CAST(date_started AS datetime), 103)
I have also tried
convert(date_started as datetime, 103)
I need to make sure the output is as dd/mm/yyyy
as we're in the UK and not the mm/dd/yyyy
format
This question is related to
sql-server
sql-server-2008
tsql
date
datetime
I think that more accurate is this syntax:
SELECT CONVERT(CHAR(10), GETDATE(), 103)
I add SELECT and GETDATE() for instant testing purposes :)
Try this code:
CONVERT(varchar(15), date_started, 103)
You can do like this:
SELECT convert(datetime, convert(date, '27-09-2013', 103), 103)
If you want to return a format mm/dd/yyyy, then use 101 instead of 103: CONVERT(VARCHAR(10), [MyDate], 101)
Source: Stackoverflow.com