Hello again guys,
So I'm wondering how to calculate a persons age? I have a character field (DateOfBirth- stored as YYYMMDD format) and I want to check that against the system date(or hardcode todays date) then put that difference (the age) into my table.
I've tried to use the TO_DATE function as well as cast. But if I do get a query to work my results come out as all ++++++++++.
Here are some examples I've tried:
select ('20120118' - DateOfBirth) as age from jkenny/medoc3
select current_date - to_date(DateOfBirth,'DDMMYY' ) as age from jkenny/medoc3
select to_date(current_date,'DDMMYY') - to_date(DateOfBirth,'DDMMYY') as age from jkenny/medoc3
select current_date - cast(DateOfBirth as date) as age from jkenny/medoc3(this example will give me ++++++++++++ as results.
Any suggestions? I'm running this as a straight query, NOT in an actual program.
So I'm wondering how to calculate a persons age? I have a character field (DateOfBirth- stored as YYYMMDD format) and I want to check that against the system date(or hardcode todays date) then put that difference (the age) into my table.
I've tried to use the TO_DATE function as well as cast. But if I do get a query to work my results come out as all ++++++++++.
Here are some examples I've tried:
select ('20120118' - DateOfBirth) as age from jkenny/medoc3
select current_date - to_date(DateOfBirth,'DDMMYY' ) as age from jkenny/medoc3
select to_date(current_date,'DDMMYY') - to_date(DateOfBirth,'DDMMYY') as age from jkenny/medoc3
select current_date - cast(DateOfBirth as date) as age from jkenny/medoc3(this example will give me ++++++++++++ as results.
Any suggestions? I'm running this as a straight query, NOT in an actual program.




Comment