MySql查询两个时间点之间的日期列表

数据库 投稿 36200 0 评论

MySql查询两个时间点之间的日期列表

本文介绍基于mysql语句MySql查询两个时间点之间的日期列表,通过代码案例教你如何实现MySql查询两个时间点之间的日期列表,让你能快速查询出MySql查询两个时间点之间的日期列表,希望能帮助大家。

Mysql查询两个日期(时间点)之间的日期列表。

select * from
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where selected_date between '2021-02-25' and '2021-03-05';

返回结果如下:

+---------------+
| selected_date |
+---------------+
| 2021-02-25    |
| 2021-02-26    |
| 2021-02-27    |
| 2021-02-28    |
| 2021-03-01    |
| 2021-03-02    |
| 2021-03-03    |
| 2021-03-04    |
| 2021-03-05    |
+---------------+
9 rows in set (0.094 sec)

编程笔记 » MySql查询两个时间点之间的日期列表

赞同 (47) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽