简体   繁体   English

如何在MySQL中根据日期从表中选择数据?

[英]How to select data from table according to dates in MySQL?

I have a table called tasks . 我有一张桌子叫tasks In the index file all the tasks are being listed. 在索引文件中列出了所有任务。 There is a column name date in tasks . tasks有一个列名date The date is saved in YYYY-MM-DD format. 日期以YYYY-MM-DD格式保存。 I want to get all the rows whose date is 2016- numbers-from-0-to-12 - numbers-from-0-to-30 . 我想获取日期为2016- 数字从0到12- 数字从0到30的所有行

example date is: 日期示例为:

2016-12-1

You can simply filter the records by specifying date range. 您只需指定日期范围即可过滤记录。

SELECT * 
FROM tasks
WHERE date BETWEEN '2016-01-01' AND '2016-12-31'
ORDER BY date DESC

Update 更新

To get records from current date: 要获取当前日期的记录:

SELECT * 
FROM tasks
WHERE date BETWEEN curdate() AND '2016-12-31'
ORDER BY date DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM