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.
Author |
Topic |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-07-12 : 03:48:14
|
A table contains a field of type smalldatetimeThe feed has this field as string i.e. '060830'Would like to insert this string date into the field of the table which has a datatype of smalldatetime.Is this the correct way to convert a string to smalldatetime?declare @DateFeed varchar(6)declare @TradeDate smalldatetimeset @DateFeed = '060830'set @TradeDate = convert(smalldatetime, 6 + '-' + 8 + '-' + 30)print @TradeDateThanks |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-12 : 03:50:43
|
[code]SELECT @TradeDate = CONVERT(smalldatetime, @DateFeed)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-07-12 : 03:58:39
|
I get this:Feb 14 1900 12:00AMwhereas the string being passed is different as you see in th first post.Thanks |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-07-12 : 04:00:44
|
Solved. thanks. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-12 : 04:10:00
|
Also you should make sure that the string has YYMMDD format, otherwise you may get different result when you convert to smalldatetimeMadhivananFailing to plan is Planning to fail |
 |
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2007-07-13 : 00:57:13
|
quote: Originally posted by arkiboys Solved. thanks.
Don't be stingy... post your solution!--Jeff Moden |
 |
|
|
|
|