CAST a variable into a datetime object
I need to do a CAST(@.variable_name as datetime)
this won't work because @.variable_name has the following format
'dd/mm/yy hh:mi:ss:mmmAM'
like how do i specify a style for it.
please help..
James : (You can use default values (style 0 or 100) to represent, refer to books online for CAST & CONVERT topic.
HTH.|||My suggestion is to write some code (which could be a transact-sql expression) to convert your chacter date to a standard form. I would strongly suggest using the ISO standard 'yyyy-mm-dd hh:mm:ss.ttt" format. I've seen a euro-to-ISO time function, if you can't find it, I can either find or write one for you.
-PatP|||hi
thanx for the reply.
books online wasn't of much help because it didn't provide any examples of converting a string to datetime. but, I have found the following to work.
convert (datetime, '30/12/04 1:10:30:000PM', 3);
i remember i used to use a combination of convert and cast to get datetime conversion working. I am just surprised that format such as
'dd/mm/yyyy' is not automatically supported in ms sql server. I had to parse the string so that i get dd/mm/yyyy in order for the conversion to work.
thanx for helping.
james : )|||Originally posted by Pat Phelan
My suggestion is to write some code (which could be a transact-sql expression) to convert your chacter date to a standard form. I would strongly suggest using the ISO standard 'yyyy-mm-dd hh:mm:ss.ttt" format. I've seen a euro-to-ISO time function, if you can't find it, I can either find or write one for you.
-PatP
hi, it would be good if you can show me how it's done, i don't know how to do any string manipulation in mssql.
thank you.
james :)
No comments:
Post a Comment