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
 General SQL Server Forums
 New to SQL Server Programming
 Convert birthday field

Author  Topic 

pamyral_279
Posting Yak Master

143 Posts

Posted - 2012-02-15 : 20:42:33
Hi all,

I have old database before , structure as :
ID Name Birthday
Birthday field is string type ! ( such as 2/1983, 10/1982,6/1979 ..)
Now how to convert to birthday string type into birthday datetime type ?

Thank you very much.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-15 : 20:52:56
is the value all in same format month/year ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pamyral_279
Posting Yak Master

143 Posts

Posted - 2012-02-15 : 22:16:48
Yes. Exactly all values are the same format month/year !

Can you help me ?
Thank you .
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-15 : 22:38:54
[code]
select convert(datetime, '1/' + Birthday, 5)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pamyral_279
Posting Yak Master

143 Posts

Posted - 2012-02-16 : 03:55:52
It show me error :
'Conversion failed when converting date and/or time from character string'
Birthday field in my db is nvarchar type !
Can you correct error for me ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-16 : 04:00:10
try use style 105 instead of 5

If it is still not working, you might have data that is not in the m/yy format or bad data.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -