我如何获得使用MYSQL和PHP在本周,本月和下个月庆祝生日的朋友的生日? [英] How would I get the birthdays of friends who are celebrating their birthday this week, this month and next month using MYSQL and PHP?

查看:146
本文介绍了我如何获得使用MYSQL和PHP在本周,本月和下个月庆祝生日的朋友的生日?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个网站上工作,该网站需要使用MYSQL和PHP获取本周,本月和下个月庆祝生日的朋友的生日.

I am currently working in an site which needs to get the birthdays of friends who are celebrating their birthday this week, this month and next month using MYSQL and PHP.

我将如何处理?

推荐答案

如果您将生日以DATE(或DATETIME)格式存储在MySQL中,则可以使用以下查询:

Provided you store birthdates in DATE (or DATETIME) format in MySQL you can use the following Queries:

// This week
SELECT * FROM person WHERE WEEK( birthdate ) = WEEK( NOW() )

// This month
SELECT * FROM person WHERE MONTH( birthdate ) = MONTH( NOW() )

// Next month

SELECT * FROM人,其中MONTH(生日)= MONTH(NOW())+ 1;

SELECT * FROM person WHERE IF
  ( MONTH( NOW() ) < 12, MONTH( birthdate ) = MONTH( NOW() ) + 1,
  MONTH( birthdate ) = 1)

这篇关于我如何获得使用MYSQL和PHP在本周,本月和下个月庆祝生日的朋友的生日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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