php Mysql 选择特定日期后的查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7249931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:19:23  来源:igfitidea点击:

Mysql select query after certain date

phpmysqlselect

提问by Henry

I am trying to pull records after a certain date using mysql query , the field type is date in my database and the query is

我正在尝试使用 mysql 查询在某个日期之后提取记录,字段类型是我数据库中的日期,查询是

SELECT * FROM tickets WHERE created_on > 26-08-2011

But it is not working and also showing all before that date

但它不起作用并且还在该日期之前显示所有内容

Thanks

谢谢

回答by James Allardice

The date you are using is a string, so it needs to be placed inside quotes. Also, the format is the wrong way around:

您使用的日期是一个字符串,因此需要将其放在引号内。此外,格式是错误的:

SELECT * FROM tickets WHERE created_on > '2011-08-26'

For more information, see the MySQL docs. In particular, note the very first line:

有关更多信息,请参阅MySQL 文档。特别要注意第一行:

The format of a DATE value is 'YYYY-MM-DD'. According to standard SQL, no other format is permitted.

DATE 值的格式为“YYYY-MM-DD”。根据标准 SQL,不允许使用其他格式。

回答by Jordi

The date is defined in yyyy-mm-dd, so you should use the date as 2011-08-26. Using a date in this format is ideal for sorting as the numbers are arranged as incremental pieces. You have to use quotes on string values, see the post of James Allardice.

日期在 yyyy-mm-dd 中定义,因此您应该使用日期为 2011-08-26。使用这种格式的日期非常适合排序,因为数字是按增量排列的。您必须在字符串值上使用引号,请参阅 James Allardice 的帖子。

回答by alresave

Try using quotes on the date and write dates in yyyy-mm-dd format for best results. '2011-08-26'

尝试在日期上使用引号并以 yyyy-mm-dd 格式写入日期以获得最佳结果。'2011-08-26'