Convert varchar dd/mm/yyyy to dd/mm/yyyy datetime
113,286
I think you are after this:
CONVERT(datetime, date_as_string, 103)
Notice, that datetime
hasn't any format. You think about its presentation. To get the data of datetime
in an appropriate format you can use
CONVERT(varchar, date_as_datetime, 103)
Author by
Stew
Updated on July 09, 2022Comments
-
Stew almost 2 years
I'm trying to convert a date in a
varchar
column in thedd/mm/yyyy
format into the datetimedd/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 themm/dd/yyyy
format -
Stew over 10 yearsDidnt work im afraid, it converted but when i added the > '01/06/2013' part to it, i was seeing dates back in 2011
-
DrCopyPaste over 10 years@Stew what do you mean with the "> '01/06/2013'"-part you did not mention anything about that in your OP what did you do with it?
-
Stew over 10 yearsThats what i had before, sorry. my mistake That also converts, but when i do a > '01/06/2013' on the date im seeing dates in january.
-
Stew over 10 yearsSELECT date_started FROM staff WHERE (CONVERT(datetime, date_started, 103) > '01/06/2013') When i do this im seeing dates in January, not after 1st June 2013
-
Jazzy J over 10 years> CONVERT(datetime, '01/06/2013', 103) - then everything is in datetime and the comparison is done on datetime datatypes.
-
senthilkumar2185 over 10 yearsit is automatically 01 is taking January month so that problem arise you convert 06/01/2013 is working