[英]php and mysql use the date range can not show
I had the question for the mysql date between select. 我有选择之间的mysql日期的问题。 In the mysql table, the field is varchar.
在mysql表中,该字段为varchar。 The date range is '21-01-2013' and '31-01-2013', it can show the records, but the date range is '21-01-2013' and '20-02-2013', it cannot show the records.
日期范围是'21 -01-2013'和'31 -01-2013',可以显示记录,但日期范围是'21 -01-2013'和'20 -02-2013',它不能显示记录。
"SELECT * from away_from_office where (awaydatefrom between '21-01-2013' and '31-01-2013') ";
you should convert it to date first using STR_TO_DATE
, eg. 您应该首先使用
STR_TO_DATE
将其转换为日期,例如。
SELECT *
from away_from_office
where awaydatefrom between STR_TO_DATE('21-01-2013', '%d-%m-%Y') and
STR_TO_DATE('31-01-2013', '%d-%m-%Y')
if the column has the same format with the one you've shown, convert it also 如果该列与您显示的列具有相同的格式,请同时对其进行转换
WHERE STR_TO_DATE(awaydatefrom, '%d-%m-%Y') BETWEEN
if you have a chance to alter the table, or you're working with sample records, alter your table by changing the data type of the column to DATE
. 如果您有机会更改表,或者您正在处理示例记录,请通过将列的数据类型更改为
DATE
来更改表。
Change column datatype to DATE
将列数据类型更改为
DATE
http://dev.mysql.com/doc/refman/5.1/en/datetime.html http://dev.mysql.com/doc/refman/5.1/zh-CN/datetime.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.