[英]MYSQL query using LIKE function for date
I have the following statement in the where statement of a mysql query: 我在mysql查询的where语句中有以下语句:
WHERE scrap_date LIKE '%-01-%'
I want to grab all the data with the scrap_date being in January. 我想使用scrap_date在一月份获取所有数据。 The error I recieve is:
我收到的错误是:
"Incorrect datetime value: '%-01-%' for column 'scrap_date' at row 1"
“错误的日期时间值:第1行的'scrap_date'列的'%-01-%'”
The datatype for scrap_date
is DATETIME
. scrap_date
的数据类型为DATETIME
。 Not sure what syntax to use to get data with the a date in January, any suggestions? 不知道要使用什么语法来获取日期为一月的数据,有什么建议吗?
您可以尝试以下方法:
select * from your table WHERE MONTH(scrap_date) = 1
You can use the DATEPART() function 您可以使用DATEPART()函数
SELECT * FROM table
WHERE (DATEPART(mm, scrap_date) = 01)
使用月份功能
WHERE MONTH(scrap_date) = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.