PHP:从年龄计算生日 [英] PHP: calculating birthday from age

查看:139
本文介绍了PHP:从年龄计算生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,这听起来很奇怪。

Yes, this may sound strange.

在高级个人资料搜索表单中,您可以按年龄进行过滤。

In the advanced profile searching form, where you can filter by age.

现在你可以在字段中输入18或其他年龄。

Now you would type 18 or some other age in the field.

我将生日存储在mysql db中的用户i的生日字段中例如:1990-02-02

I am storing the birthdays, in the mysql db, in the birthday field in users i have example: 1990-02-02

如何在查询中按年龄筛选?

How can i filter by age then, in a query?

如果我先做一个查询,让所有用户的生日达到年龄,然后比较他们?

Should i first make a query before, make all users birthdays to age, and then compare them? Would be too much, to take each one user.

推荐答案

我打赌这是你正在寻找的:

I bet this is what you are searching for:

SELECT * FROM mytable 
WHERE TIMESTAMPDIFF(YEAR, mytable.birthday,'$currentTime') > '$ageFromForm';

要对数据进行排序,请执行以下操作:

To sort the data you would perform this :

SELECT *, (TIMESTAMPDIFF(YEAR, mytable.birthday, '$currentTime')) AS age 
FROM mytable WHERE TIMESTAMPDIFF(YEAR,'$birthday','$currentTime') > '$ageFromForm' 
ORDER BY age;

我希望这会有帮助;)
Slavic

I hope this helps ;) Slavic

这篇关于PHP:从年龄计算生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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