Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert varchar dd/mm/yyyy to dd/mm/yyyy datetime

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

like image 965
Stew Avatar asked Oct 11 '13 09:10

Stew


1 Answers

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)
like image 53
Hamlet Hakobyan Avatar answered Sep 23 '22 02:09

Hamlet Hakobyan