匹配日期-生日
我正在执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法可能是将 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()))))