How to find age with the sqlyear function

Please tell me how to go through the date of birth from sqlserver database and then calculate his age?

Calculating age from date of birth in SqlServer

is available in

year function

.

Tools: SqlServer

2008

R2

Steps:

1, there is student table, the data is as follows, where birthday column is the birthday column:

2, to calculate the age of each person, available as the following statement:

select*, year(getdate), year(getdate). year(getdate())-year(birthday)agefromstudent3, the query results are as follows, age calculation results appear:

How to get age in a database with only date of birth?

Year(Now())-year([date of birth]).

Calculating age from date of birth can be done with the year function.

SqlServer can calculate age from date of birth with year function. Steps are as follows: There is student table with the following data, where birthday column is birthday column. To calculate the age of each person, the following statement: the query results are as follows, the age of the results appear: a relational database system introduced by Microsoft Corporation.

To give you an idea, first you need to convert the date of birth to to_char format, and then subtract the current date can be.

Database known date of birth for the average age with the YEAR function. According to the query related to public information shows that the date of birth through the calculation of age available year function, is very convenient. Function, a mathematical term.

In EXCEL, know the month and year of birth, you can use the Today function and YEAR function to calculate the age. Method steps are as follows: open the need to operate the EXCEL form, in any blank position above the function edit box enter “= YEAR (TODAY ()) – YEAR (A1)”, and press Enter.

Problem with function YEAR in SQL

select

(year(getdate())-table name. Age+1)

from

Table name

Then you can directly return a column of years without inserting a separate column

If you want to query the school number and the year of the voice can be directly like this:

select

School number,(year(getdate())-table name. Age+1)

from

Table Name.

sql calculate age based on birthdate

SQL calculate age:

SELECTFLOOR(DATEDIFF(CURDATE(),STR_TO_DATE(birthday,’%Y-%m-%d’))/365)ASageFROMtable_name;

p>Expansion: MySQL can use the TIMESTAMPDIFF function to calculate the age based on the date of birth, it accepts 5 parameters:

TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2,[datetime_expr3],[ datetime_expr4])

The unit parameter can be any of YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, representing the unit in which the result is calculated.