MYSQL 选择日期早于日期时间的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10565924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MYSQL Select rows where date is older than datetime
提问by André Figueira
I am coding a status item for a website and need to load statuses older than a variable that contains a datetime.
我正在为网站编码状态项,需要加载比包含日期时间的变量更旧的状态。
So the database has a field called added date which is a datetime field and I have a string in datetime format and i want to select all rows older than my datetime format string.
所以数据库有一个名为添加日期的字段,它是一个日期时间字段,我有一个日期时间格式的字符串,我想选择比我的日期时间格式字符串早的所有行。
How would this be structured in MYSQL?
这将如何在 MYSQL 中构建?
Thanks in advance.
提前致谢。
回答by juergen d
select status_column from your_table
where added_date < '2012-05-12'
回答by Moyed Ansari
mysql DATETIME type is used for values that contain both date and time parts.
mysql DATETIME 类型用于包含日期和时间部分的值。
Try this
尝试这个
SELECT datecolumn
FROM table
WHERE datetime_date > '2012-05-12 01-32-56'
回答by M.I.T.
try this
尝试这个
$today = date('Y-m-d');
SELECT column_name FROM table_name WHERE year(added_date) > $today AND month(added_date) > $today