Get difference in years between two dates in MySQL as an integer

后端 未结 9 2062
死守一世寂寞
死守一世寂寞 2020-11-30 10:59

I am trying to calculate how old is a person in a database.
Let\'s suppose to have this simple table:

student(id, birth_date);

Where

9条回答
  •  盖世英雄少女心
    2020-11-30 11:37

    For anyone who comes across this:

    another way this can be done is:

    SELECT TIMESTAMPDIFF(YEAR, date_of_birth, CURDATE()) AS difference FROM student
    

    For differences in months, replace YEAR with MONTH, and for days replace YEAR with DAY

    Hope that helps!

提交回复
热议问题