PHP:从年龄计算生日

编程入门 行业动态 更新时间:2024-10-27 08:36:56
本文介绍了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:从年龄计算生日

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

发布评论

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

>www.elefans.com

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