如何通过MySQL查询使用BirthDate列获取Age? [英] How to get Age using BirthDate column by MySQL query?

查看:519
本文介绍了如何通过MySQL查询使用BirthDate列获取Age?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL数据库表中有一个BirthDate列来存储用户的出生日期。现在我在html / php中有两个字段(1。Age From 2. Age To)。

I have a BirthDate column in MySQL database table to store user's date of birth. Now I have form in html/php with two fields(1. Age From 2. Age To).

如果用户希望让所有用户的年龄在10到20年之间,那么可以通过使用BirthDate列的MySQL查询来做到这一点。

If user want to get all users where their ages are between 10 years and 20 years, Is it possible to do this with MySQL query using BirthDate column.

谢谢

推荐答案

您的查询将类似于: / p>

Your query would look similar to this:

SELECT * FROM your_table WHERE YEAR(CURDATE())-YEAR(BirthDate) BETWEEN 10 AND 20;

这篇关于如何通过MySQL查询使用BirthDate列获取Age?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆