I have a string \'2009-06-24 09:52:43.000\', which I need to insert to a DateTime column of a table.
But I don\'t care about the time, just want to insert it as 2009-06-
James is correct. If you're starting off with a string, and the format will always be what you say it is, then you keep it simple and efficient. Use LEFT( @StrDate, 10)
and CONVERT
that to your datetime value. Done.
If your input string could be any valid date/time format, then you have to use CONVERT(datetime, @StrDate)
first. After that you go with what Bing just said to strip off the time part.