gpt4 book ai didi

mysql - 比较 MySQL 中的日期

转载 作者:行者123 更新时间:2023-11-29 21:02:58 24 4
gpt4 key购买 nike

我想比较数据库中两个给定日期之间的日期。数据库中的列是 DATETIME,我只想将其与日期格式进行比较,而不是与日期时间格式进行比较。

SELECT * FROM `players` WHERE CONVERT(CHAR(10),us_reg_date,120) >= '2000-07-05' AND CONVERT(CHAR(10),us_reg_date,120) <= '2011-11-10'

当我执行上面的 SQL 时,出现此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'us_reg_date,120) >= '2000-07-05' AND CONVERT(CHAR(10),us_reg_date,120) <= '2011-' at line 1

如何解决这个问题?

最佳答案

您可以尝试以下查询,

select * from players
where
us_reg_date between '2000-07-05'
and
DATE_ADD('2011-11-10',INTERVAL 1 DAY)

关于mysql - 比较 MySQL 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37054205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com