|
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'):
(comments are locked)
|
|
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. gah, the style parameter, good catch.
May 20 '10 at 04:58 AM
Fatherjack ♦♦
Thank u ..that was quick..
May 20 '10 at 08:51 PM
Neha 1
(comments are locked)
|
|
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 +1 - I shouldn't go for breakfast in the middle of answering posts... :)
May 20 '10 at 04:57 AM
Matt Whitfield ♦♦
breakfast?! Its nearly lunchtime. You Sir, are clearly not a horse owner. :D
May 20 '10 at 05:00 AM
Fatherjack ♦♦
No, just the 4 chickens, 3 cats, 2 gerbils and 1 dog... (!)
May 20 '10 at 05:15 AM
Matt Whitfield ♦♦
Hopefully well segregated to prevent it simply becoming the owner of 1 dog ... ?!
May 20 '10 at 05:33 AM
Fatherjack ♦♦
Well I think that depends on your perspective... Certainly the eggs are nice, but I think they're pets really. It was the Gypsy Fair Day in the village I live in today, had a narrow escape as the wife almost purchased a horse...
May 20 '10 at 09:11 PM
Matt Whitfield ♦♦
(comments are locked)
|

