MySQL的日期差异来计算年龄

编程入门 行业动态 更新时间:2024-10-27 00:27:07
本文介绍了MySQL的日期差异来计算年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个关于 datediff MYSQL功能的问题,我可以使用它,它很简单。但是我不明白如何使用它来收集表格中的差异。例如

我有一个列 dob ,我想编写一个将执行类似

select dateDiff(current_timeStamp,dob) from sometable'here dob is the table column 解决方案

你的意思是这样吗?

SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),dob)),%Y)+ 0 AS age from sometable

(源)

I have a problem regarding the datediff MYSQL function, I can use it and it is simple. But I don't understand how to use it to collect differences within the table field. E.g.

I have a column dob and I want to write a query that will do something like

select dateDiff(current_timeStamp,dob) from sometable 'here dob is the table column

I mean I want the difference from the current date time to the table field dob, each query result is the difference, the age of the user.

解决方案

You mean like this?

SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), dob)), "%Y")+0 AS age from sometable

(Source)

更多推荐

MySQL的日期差异来计算年龄

本文发布于:2023-10-18 11:48:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:差异   年龄   日期   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!