9
MySql根据生日计算年龄
source link: https://www.bugcatt.com/archives/2545
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
这次的需求是需要通过出生日期(年月日)来计算年龄。一句SQL就可以搞定:
SELECT TIMESTAMPDIFF(YEAR, '2000-01-01', CURDATE());
如果格式是 年-月-日 ,那就使用CONCAT
拼接起来,这么写:
SELECT TIMESTAMPDIFF(YEAR, CONCAT(2000, '-', 1, '-', 1), CURDATE());
如果你遇到了更好的解法,欢迎在下方留言哟!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK