MySQLで年齢計算 | code225

code225

WEBプログラミングのメモ。PHP、JavaScript、HTML、MySQLなど。

MySQLでもエクセルと同じように誕生日から年齢を求める。

date_format関数を使う。


birth が誕生日フィールド
table がテーブル


SELECT birth,floor((date_format(now(), '%Y%m%d') - date_format(birth, '%Y%m%d'))/10000) nenrei
FROM `table`


これでOK