欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

计算距离生日多少天(最简便SQL语句),距离生日sql语句

来源: javaer 分享于  点击 29109 次 点评:162

计算距离生日多少天(最简便SQL语句),距离生日sql语句


select datediff(concat(substring(current_timestamp(6),1,4),substring(hbirth,5)),current_timestamp(6)) day from human where hid=1001
select datediff(concat(substring(current_timestamp(6),1,4)+1,substring(hbirth,5)),current_timestamp(6)) day from human where hid=1001

第一条SQL结果为负数说明今年的生日已经过了,则第二条SQL的结果即为距离生日天数。注:hbirth是字段

 datediff函数用来返回两个日期之间的时间差,返回值为Long类型

concat函数用来拼接字符串

substring()​​​​​​方法用来截取字符串,我这里是截取了年份

current_timestamp(6)是获取当前时间,年月日,时分秒的格式

 

相关文章

    暂无相关文章

用户点评