score:6

Accepted answer

Once you get your story straight, you'll want one of these:

-- if you really meant dd/mm/yyyy then:

SELECT CONVERT(DATETIME, '16/3/2012 4:39:26 PM', 103);

-- if you really meant mm/dd/yyyy then:

SELECT CONVERT(DATETIME, '3/16/2012 4:39:26 PM', 101);

But agreed with Madhivanan. Don't store dates using the wrong data type, and if you must, use an unambiguous format!

Read More

score:-3

This will work.

DECLARE @dt varchar(100)='2012/3/16 4:39:26 PM'
select convert(datetime,@dt,101)

score:4

  1. Always use proper DATETIME datatype to store dates
  2. YYYYMMDD and YYYYMMDD HH:MM:SS are unambiguous date formats

For more information, refer this

http://beyondrelational.com/modules/2/blogs/70/posts/10898/understanding-datetime-column-part-ii.aspx


More questions

More questions with similar tag