| Author |
Topic |
|
idontknow
Starting Member
2 Posts |
Posted - 2012-03-16 : 12:52:06
|
| Hi everybody,this part of my SQL command CONVERT(datetime, 2012-03-16 17:43:53.873, 121) throws the error "Incorrect error near '17'". What did I do wrong?EDIT: Whoops, totally forgot the ' characters. |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
idontknow
Starting Member
2 Posts |
Posted - 2012-03-16 : 13:05:02
|
| It's not a SELECT, it's an INSERT, but okay. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-03-16 : 13:10:27
|
quote: Originally posted by X002548 SELECT CONVERT(datetime, '2012-03-16 17:43:53.873', 121) Why would you add a format for it? That's meaninglessBrett8-)
It may not be needed in this case since the date string format is ODBC canonical and sql can handle that, but Meaningless? Far from it. It's always good form to specify the format when converting from a string to a date. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-03-16 : 16:13:03
|
| I'm not sure I understand your question. Are you asking why one would want to use good form and technique when programming? Or are you asking why it's good form to use a style specifier to denote what format the date string is in when converting it? Either way, the answer should be self-evident. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-03-17 : 14:26:16
|
quote: Originally posted by X002548 >> good form and technique when programmingReally?How the hell are you suppose to know the format of an input variable so you can supply the format?This makes no senseBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
If the date comes from different source with specific format in varchar datatype, it is needed to supply the format value if the date setting of the current server is differentMadhivananFailing to plan is Planning to fail |
 |
|
|
|