mysql通过生日计算年龄(同理可得通过18位身份证号计算年龄)
– 生日类型是String yyyy-mm-dd 按一年365天计算年龄SELECT birthday, FLOOR(PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m%d'), DATE_FORMAT(birthday, '%Y%m%d'))/365) AS age FROM persons;
– 生日类型是Date
SELECT birthday, TIMESTAMPDIFF(YEAR, birthday, CURDATE()) AS age FROM persons;
– 生日类型是String yyyy-mm 按一年12个月计算年龄
SELECT m.sex, mpython.card_no, m.birth_date, FLOOR(PERIOD_DIFF(DATE_FORMAT(NOW(),http://www.devze.com '%Y%m'), DATE_FORMAT(CONCAT(m.birth_date,'-01'), '%Y%m'))/12) AS age FROM tb_cloud_member m LEFT JOIN tb_cloud_laborun l on l.laborun_code=m.laborun_code LEFT JOIN tb_cloud_enterprises tce ON tce.id = m.unit_id and l.is_deleted=0 and tce.is_deleted=0 w编程客栈here 1=1 and m.is_deleted=0 and l.is_laborun =1 and m.is_new_occupation=2 AND ( m.retirement_flag IS NULL OR m.retirement_flag = '' OR m.retirement_flag = '0' OR m.retirement_flag = '2' ) AND ( m.job_status IS NULL OR m.job_status not in (4,5,6));
到此这篇关编程客栈于mysql通过生日计算年龄的文章就介绍到这了,更多相关mysql通过生日计算年龄内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(w编程客栈ww.cppcns.com)!
精彩评论