gpt4 book ai didi

php - 如何添加where子句以及如何获取两个日期的月份差异

转载 作者:行者123 更新时间:2023-11-30 01:07:36 25 4
gpt4 key购买 nike

参数时如何计算列数?

我需要计算所有客户,当您将今天的日期/当前(例如;2013-10-28)减去出生日期列(例如;2001-15-13)时返回“<= 6个月”

我有一个 mysql 查询:

$query = 'SELECT  b.record_number,
CONCAT(b.fname," ",b.lname) AS fullname,
province.area_name AS province,
district.area_name AS district,
llg.area_name AS llg,
office.area_name AS office,
c.clinic_name,
a.feeding_type,
COUNT(NOW, b.date_birth), - this is my code
b.date_birth,
FROM tbl_records AS a
JOIN tbl_client AS b ON a.client_id = b.ID
JOIN tbl_clinic AS c ON a.clinic_id = c.ID
JOIN tbl_area AS llg ON c.llg_id = llg.ID
JOIN tbl_area AS district ON llg.parent_ids = district.ID
JOIN tbl_area AS province ON district.parent_ids = province.ID
JOIN tbl_area AS office ON office.ID = a.office_id
WHERE a.date >= :start_date AND a.date <= :end_date
AND a.feeding_type <> "NULL" AND a.office_id = :office_id
GROUP BY a.client_id';

最佳答案

要获取MYSQL中日期之间的差异,可以使用DATEDIFF

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_datediff

从你的问题来看,我认为你正在尝试返回一些间隔并根据该间隔返回一个字符串。您需要设置一系列 IF 语句。

https://dev.mysql.com/doc/refman/5.0/en/if.html

更新:

您可以使用PERIOD-DIFF获得几个月的差异,但您需要更改日期的格式。您可以使用 GET_FORMAT

执行此操作

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_get-format

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_period-diff

关于php - 如何添加where子句以及如何获取两个日期的月份差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19637058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com