如何将日期与字符串进行比较
我有一个MySQL查询,我在其中尝试在Where子句中使用字符串。
select s.schedule_date
from schedule s
WHERE DATE(s.schedule_date) = '2022-06-04'
而且它行不通。
我也尝试了 s.schedule_date ='2022-06-04' 日期(s.schedule_date)= date('2022-06-04'),
但似乎无效。我看过的大多数文章都说SQL示例中的位置应起作用。
select
s.schedule_date,DATEDIFF(s.schedule_date,"2022-06-04")
from
schedule s
WHERE
s.schedule_date >= "2022-06-03" and
s.schedule_date <= "2022-06-05";
>
I have a mysql query where I am trying to use a string in the where clause.
select s.schedule_date
from schedule s
WHERE DATE(s.schedule_date) = '2022-06-04'
and it does not work.
I have also tried
s.schedule_date = '2022-06-04'
DATE(s.schedule_date) = DATE('2022-06-04')
But nothing seems to work. Most articles I have seen say the where in the SQL example should work.
select
s.schedule_date,DATEDIFF(s.schedule_date,"2022-06-04")
from
schedule s
WHERE
s.schedule_date >= "2022-06-03" and
s.schedule_date <= "2022-06-05";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,这是一个问题。我将设置nodatimestringsync设置的mySQL驱动程序更改为true。默认为false。不知道为什么它只是开始这样做
I turns out it was a DBeaver issue. I changed the MySQL driver setting noDatetimeStringSync to true. The default it false. Not sure why it just started doing this
您可以尝试使用mysql
str_to_date
函数:它将字符串转换为日期,给定输入格式,在您的情况下,应为>%y-%m-%d
。它可以解决您的问题吗?
You can try using the MySQL
STR_TO_DATE
function: it converts a string to a date, given the input format, that in your case should be%Y-%m-%d
.Does it solve your problem?
您可以使用 cast function-function,以将字符串转换为日期。当然,铸件也可以用于任何其他转换(int将字符串,char(n)的字符串,...)。就您而言,查询应该看起来像这样:
You could use the CAST-Function, to convert your strings into dates. Of course, CAST can also be used for any other transformation (INT to STRING, STRING TO CHAR(n), ...). In your case, the query should look like this: