age
function
Some database such as Postgres offer an age
function to calculate the span of time between a pair of timestamps. Passing a single timestamp means the current date-time will be used as the second of the pair.
Time Zone
You may care about time zone if you want a precise age.
For example, a new days dawns earlier in Paris than in Montréal. So if running SQL code around midnight, you will get a different result if the code runs on a server with a different current default time zone.
If you care about this level of accuracy, specify the second date in the pair. Use a function that takes a time zone to determine today’s date.
String as Date-Time Type
Ideally you should be storing date-time values as date-time types. But I'm guessing that in this Question your date is actually a textual value.
Alphabetical Order = Chronological Order
If that date-of-birth column is a text value in SQL format, parallel to ISO 8601 format, then its alphabetical ordering is also a chronological ordering. So we can directly use such ordering to find the oldest value.
LIMIT
To Get First Row
The LIMIT
command truncates the result set to the first x number of rows. Sorting by the date of birth in ascending order means we will get the first row only.
Example Code
Tip: Naming columns and other objects in SQL with a trailing underscore avoids absolutely any collision with keywords/reserved words. So promises the SQL spec.
SELECT name_ , date_of_birth_ , age( timestamp date_of_birth_ ) AS age_
WHERE sex_ = 'm'
ORDER BY date_of_birth_ ASC
LIMIT 1
;