本文介绍了我如何获得使用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 person WHERE IF
  ( MONTH( NOW() ) < 12, MONTH( birthdate ) = MONTH( NOW() ) + 1,
  MONTH( birthdate ) = 1)

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

11-02 02:23