在特定日期后获取 MySQL 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1855082/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:41:56  来源:igfitidea点击:

Getting MySQL data after specific date

mysql

提问by testkhan

How can I fetch MySQL data after a specific timestamp? What should the query look like?

如何在特定时间戳后获取 MySQL 数据?查询应该是什么样的?

mysql_query("SELECT * FROM table where TheNameOfTimestampColumn > than the date");

回答by Angel.King.47

SELECT * FROM table WHERE TheNameOfTimestampColumn > '2009-01-28 21:00:00'
SELECT * FROM table WHERE TheNameOfTimestampColumn > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY)

回答by stackFan

You can select this by :

您可以通过以下方式选择:

select * from table_name where date_column > "2001-01-01 00:00:00"

select * from table_name where date_column > "2001-01-01 00:00:00"

or if you need data within certain time frame then you can try using betweenkey word such as:

或者如果您需要特定时间范围内的数据,那么您可以尝试使用between关键字,例如:

select * from table_name where date_column 
between "2018-01-04 00:00:00" and "2018-01-04 11:59:59";

Note that date format should be in YYYY-MM-DD HH:MM:SS

请注意,日期格式应为 YYYY-MM-DD HH:MM:SS

回答by iautomation

If you're using a unix timestamp, you can do the following:

如果您使用的是 unix 时间戳,则可以执行以下操作:

SELECT * FROM table WHERE TheNameOfTimestampColumn > FROM_UNIXTIME(your_time_stamp_here)

回答by Koushik Das

You can use MySQL DATEfunction like below

您可以使用DATE如下所示的MySQL函数

For instance, if you want results after 2017-09-05

例如,如果您想要 2017-09-05 之后的结果

SELECT DATE(timestamp_field) as date FROM stocks_annc WHERE DATE(timestamp_field) >= '2017-09-05'

Make sure to wrap the date within single quotation ''

确保将日期用单引号括起来 ''

Hope this helps.

希望这可以帮助。