Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello,I need to convert a string to datetime...the thing is I use a middleware to process the sql. For that reason my format can't have spaces or : in it.One year ago I used this format:2012-09-12T13_23_56 it as perfect..but now it' ot working anymore...does anbody another format which fits my requirement?In addition to that I tried to concat a query myself:SELECT convert(datetime,'2012-09-12T13'+':'+'23'+':'+'56'+':'+'333')But it didn't work. Can anybody help me?Kind regards,Lara
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-09-12 : 09:17:18
You should be able to use style 126 to convert and get a string without any spaces. For example:
SELECT CONVERT(VARCHAR(32),GETDATE(),126);
returns this:
2012-09-12T09:16:45.767
Edit: If you don't want the fractional part, use one of these to trim off that:
quote:Originally posted by musclebreast Hello,I need to convert a string to datetime...the thing is I use a middleware to process the sql. For that reason my format can't have spaces or : in it.One year ago I used this format:2012-09-12T13_23_56 it as perfect..but now it' ot working anymore...does anbody another format which fits my requirement?In addition to that I tried to concat a query myself:SELECT convert(datetime,'2012-09-12T13'+':'+'23'+':'+'56'+':'+'333')But it didn't work. Can anybody help me?Kind regards,Lara
<<the thing is I use a middleware to process the sql>>What is that middleware? You should always pass date values using a proper DATE or DATETIME parameterMadhivananFailing to plan is Planning to fail