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, m.card_no, m.birth_date, floor(period_diff(date_format(now(), '%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 where 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通过生日计算年龄内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论