当前位置: 代码网 > it编程>数据库>Mysql > mysql通过生日计算年龄的实现方法

mysql通过生日计算年龄的实现方法

2024年11月25日 Mysql 我要评论
mysql通过生日计算年龄(同理可得通过18位身份证号计算年龄)– 生日类型是string yyyy-mm-dd 按一年365天计算年龄select birthday, floor(p

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通过生日计算年龄内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网! 

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com