gpt4 book ai didi

php - MySQL - 如何显示特定月份的所有天数记录?

转载 作者:行者123 更新时间:2023-11-29 04:19:16 25 4
gpt4 key购买 nike

select a.Date 
from (
select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where a.Date between '2015-04-15' and '2015-05-15' ORDER BY Date

以上查询工作正常我从选定日期到选定日期获得 30 条记录。但我想显示完整的月份记录。如果我选择 February 那么所有 28 天(如果是闰年则为 29 天)记录都会显示。与 Mar = 31 记录 April = 30 记录相同。等

编辑: 查看截图。我想显示一个月中的所有天数。

enter image description here

如果可能,请使用 PHP 发布您的答案。

最佳答案

如果你知道你输入的年份和月份那么你总是可以设置第一天,假设输入是 Y = 2012 M=02 ,第一天总是 2012-02 -01 并使用该日期可以获得最后一天,然后是该范围内的日期。作为

select a.Date 
from (
select last_day('2012-02-01') - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where a.Date between '2012-02-01' and last_day('2012-02-01') order by a.Date;

+------------+
| Date |
+------------+
| 2012-02-01 |
| 2012-02-02 |
| 2012-02-03 |
| 2012-02-04 |
| 2012-02-05 |
| 2012-02-06 |
| 2012-02-07 |
| 2012-02-08 |
| 2012-02-09 |
| 2012-02-10 |
| 2012-02-11 |
| 2012-02-12 |
| 2012-02-13 |
| 2012-02-14 |
| 2012-02-15 |
| 2012-02-16 |
| 2012-02-17 |
| 2012-02-18 |
| 2012-02-19 |
| 2012-02-20 |
| 2012-02-21 |
| 2012-02-22 |
| 2012-02-23 |
| 2012-02-24 |
| 2012-02-25 |
| 2012-02-26 |
| 2012-02-27 |
| 2012-02-28 |
| 2012-02-29 |
+------------+
29 rows in set (0.00 sec)

关于php - MySQL - 如何显示特定月份的所有天数记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30300664/

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