比较MySQL中的日期 [英] Compare dates in MySQL

查看:107
本文介绍了比较MySQL中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to compare a date from a database that is between 2 given dates. The column from the database is DATETIME, and I want to compare it only to the date format, not the datetime format.

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时收到此错误:

I get this error when I execute the SQL above:

您的SQL语法有错误; 检查对应的手册 您的MySQL服务器版本 在附近使用正确的语法 'us_reg_date,120)> ='2000-07-05'并且 CONVERT(CHAR(10),us_reg_date,120)< = 第1行的"2011-"

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

如何解决此问题?

推荐答案

您可以在下面的查询中尝试

You can try below query,

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

这篇关于比较MySQL中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆