dthree
dthree

Reputation: 20730

T-SQL convert messed-up date string

I have a (temp) column stored as a varchar with fields in the following date format:

24/07/2005 14:19:54

When I cast this as a date, it mixes up the day and month - gets them backwards. I need to convert them all to standard date SQL (YYYY-MM-DD ...), and I can't figure out the best way to do this.

Upvotes: 0

Views: 94

Answers (1)

aucuparia
aucuparia

Reputation: 2051

Use CONVERT instead of CAST. CONVERT allows you to choose a format:

convert(datetime,'13/12/2012 10:31:01',103)

Formats are listed in the MSDN docs; 103 is British (i.e. dd/mm/yyyy).

Upvotes: 5

Related Questions