匹配日期-生日

发布于 2024-11-04 04:24:22 字数 359 浏览 0 评论 0原文

我正在执行 mysql 查询并尝试获取与当前日期和月份匹配的生日。

这是我正在尝试的,但意识到它无法正常工作:

$birthdays = $wpdb->get_results(" SELECT * FROM {$wpdb->usermeta} WHERE meta_key = 'birthday' AND meta_value >= UNIX_TIMESTAMP(DATE(NOW()))");

当然,如果生日是在今年,这会拉出生日(不是我需要的)。生日存储在数据库中为 1304035200

任何帮助将不胜感激。我已经阅读了许多相关帖子,但它们对我的需要没有帮助。

I am doing a mysql query and trying to get birthdays that match the current day and month.

Here is what I was trying but realized that it wont work properly:

$birthdays = $wpdb->get_results(" SELECT * FROM {$wpdb->usermeta} WHERE meta_key = 'birthday' AND meta_value >= UNIX_TIMESTAMP(DATE(NOW()))");

This will pull a birthday of course if the birthday is in this year (not what I need). the birthday is stored in the db as 1304035200

Any help would be greatly appreciated. I have read many of the related posts but they do not help with what I need.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁绊已千年 2024-11-11 04:24:23

最简单的方法可能是将 unix 时间戳转换为日期,并将其月份和日期值与今天的月份和日期值进行比较。我使用的是 iPhone,所以请原谅格式/打字错误,但我认为以下应该可行(在妻子购物时等待她:))

SELECT * FROM {$wpdb->usermeta} WHERE meta_key = '生日' AND ((MONTH(FROM_UNIXTIME(meta_value)) = MONTH(DATE(NOW()))) AND (DAY(FROM_UNIXTIME(meta_value)) = DAY(日期(现在()))))

The easiest way might be to convert the unix timestamp to a date and compare it's month and day values with the month and day values of today. I'm on my iPhone so forgive formatting/typos but I think the following should work (waiting for the wife while she shops :))

SELECT * FROM {$wpdb->usermeta} WHERE meta_key = 'birthday' AND ((MONTH(FROM_UNIXTIME(meta_value)) = MONTH(DATE(NOW()))) AND (DAY(FROM_UNIXTIME(meta_value)) = DAY(DATE(NOW()))))

灵芸 2024-11-11 04:24:23
select * from table where from_unixtime(field,'%m-%d') = right(curdate(),5)

$birthdays = $wpdb->get_results(" SELECT * FROM {$wpdb->usermeta} WHERE meta_key = 'birthday' and from_unixtime(meta_value,'%m-%d') = right(curdate(),5) "); 
select * from table where from_unixtime(field,'%m-%d') = right(curdate(),5)

$birthdays = $wpdb->get_results(" SELECT * FROM {$wpdb->usermeta} WHERE meta_key = 'birthday' and from_unixtime(meta_value,'%m-%d') = right(curdate(),5) "); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文