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 |
calpolyjeff
Starting Member
3 Posts |
Posted - 2010-01-05 : 17:58:45
|
An alphanumeric ID Number that I have in my ADP/SQL database contains within it 6 characters representing the birth date. So of you were born today, your ID would include 010510, as in mmddyy.I can extract those 6 digits using SUBSTRING(), but I can't seem to get them to convert to a date data type (so I can test for the age of the person). As an experiment, I used a today's date in this expression:CONVERT (DATETIME, '010510')and got "May 10 2001 12:00AM" as the output. Obviously, the function did not read my string as mmddyy, but as yymmdd. What I want is for the output to be "01/05/10." Is this possible?Thanks! |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-06 : 01:26:25
|
Use one of the methodsdeclare @date varchar(8)set @date='010510'select convert(datetime,stuff(stuff(@date,3,0,'-'),6,0,'-'))select cast(stuff(@date,1,4,left(year(getdate()),2))+left(@date,4) as datetime)MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|