A table in my database has date stored in varchar(50) column.The date is '22/09/2009 13:15:13'.How do i convert it to datetime.I am getting an error when i try to select CONVERT(datetime,'22/09/2009 13:15:13'):
Use the third parameter to CONVERT, the style parameter.
For your particular style, you want to use style 103:
For more information, see the reference here: http://msdn.microsoft.com/en-us/library/ms187928.aspx
A good practice is always to use the ISO format of 'yyyymmdd' when using text dates, as that can't be mis-interpreted, and also sorts naturally in date order when using a text sort.
answered May 20, 2010 at 04:55 AM
Matt Whitfield ♦♦
Its because the value is being read in the format mm/dd/yyyy and there isnt a 22nd month. If you change the format of the supplied date it should be fine
hope this helps
answered May 20, 2010 at 04:33 AM