MySQL - SELECT WHERE date< X [英] MySQL - SELECT WHERE date < X

查看:195
本文介绍了MySQL - SELECT WHERE date< X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MySQL中执行此操作?

How do I do this in MySQL?

 SELECT * FROM MyTable WHERE MyDateCol < TODAY()

我在这个主题上搜了很多,没有找到任何东西,除了看MySQL日期参考,这不足以解释上述情况。

I googled a lot on the subject and didn't really find anything except "look in the MySQL date ref" which does not explain the above easily enough.

我知道我可以做以下这些是间接的:

I know I can do the following which is kinda indirect:

SELECT * FROM MyTable WHERE MyDateCol BETWEEN (0000-00-00) AND TODAY()


推荐答案

在MySQL中,您有 curdate() 功能,这将让你今天的日期

In MySQL, you have the curdate() funciton, that will get you the date of today.

所以,这样做应该做:

select *
from your_table
where your_date_column < curdate()



引用该手册的该功能页面:


Quoting the manual's page of that function :


将当前日期作为
'YYYY-MM-DD'或 YYYYMMDD 格式,
取决于函数是否在字符串或数字上下文中使用

Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context.



如果要比较当前时间(而不仅仅是日期),您可以使用 now() 功能:


And if you want to compare to the current time (and not only day), you can use the now() function :


将当前日期和时间作为
返回到code>'YYYY-MM-DD HH:MM:SS'

YYYYMMDDHHMMSS.uuuuuu 格式

这篇关于MySQL - SELECT WHERE date&lt; X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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