The AGE function is used to calculate the age difference between a specified date and another date. The syntax is: AGE(date_column, date_to_compare, [age_unit]). Parameters include the date column for which the age difference is to be calculated, the date used for comparison, and an optional age unit (default is years). Please note when using this function that a negative value means that date_to_compare occurs before date_column, and the AGE function only applies to date type data.
AGE function in SQL
What is the AGE function?
The AGE function calculates the age difference between a specified date and another date.
Syntax:
<code class="sql">AGE(date_column, date_to_compare, [age_unit])</code>
Parameters:
Example:
<code class="sql">SELECT AGE(birthdate, GETDATE()) AS age_in_years FROM Person;</code>
This query calculates the age (in years) of each person in the Person
table and stores it In the age_in_years
column.
Note:
date_to_compare
occurs before date_column
, the function will return a negative value. age_unit
is not specified, years will be used as the unit by default. The above is the detailed content of What does age mean in sql. For more information, please follow other related articles on the PHP Chinese website!