RanLevy
asked on
How do I select records with a given date type field older than a specific date ?
I Have a table of persons that includes date of birth.
I want to select people of a specific age (e.g. - over 40).
What is the correct SQL syntax ?
I want to select people of a specific age (e.g. - over 40).
What is the correct SQL syntax ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depends on what you mean by over 40. This would give you people that are at least 40 years old.
WHERE dateOfBirthColumn <= dateAdd('yyyy', -40, date())
WHERE dateOfBirthColumn <= dateAdd('yyyy', -40, date())
I have no problem with Limbeck's suggestion, but again it depends on what the asker meant by over 40.
In terms of age, "over" often means X years of age old OR older. If that's what was meant, they should use the code in my suggestion. It finds people 40 years old or older. If they want to find individuals that are 40 years old _plus_ 1 day they should use Limbeck's suggestion.
Of course if they want people that are 41 years of age or older, both suggestions are wrong ;-)
In terms of age, "over" often means X years of age old OR older. If that's what was meant, they should use the code in my suggestion. It finds people 40 years old or older. If they want to find individuals that are 40 years old _plus_ 1 day they should use Limbeck's suggestion.
Of course if they want people that are 41 years of age or older, both suggestions are wrong ;-)
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
ASKER