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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Convert varchar to date

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-07-12 : 03:48:14
A table contains a field of type smalldatetime
The 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 smalldatetime

set @DateFeed = '060830'

set @TradeDate = convert(smalldatetime, 6 + '-' + 8 + '-' + 30)
print @TradeDate

Thanks

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]

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-07-12 : 03:58:39
I get this:
Feb 14 1900 12:00AM

whereas the string being passed is different as you see in th first post.
Thanks
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-07-12 : 04:00:44
Solved. thanks.
Go to Top of Page

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 smalldatetime

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -