简体   繁体   English

SQL选择created_at大于日期的行

[英]SQL Select rows where created_at is greater than a date

I am getting very odd results running the following query: 运行以下查询,我得到非常奇怪的结果:

select * from "statuses" where "created_at" > '2015-04-26 02:04:24';

this seems to returning the following dates: 这似乎返回以下日期:

2015-04-26 10:44:04
2015-04-26 12:19:47
2015-04-26 12:20:12

as you can see these are actually below the specified DATE/TIME i entered. 如您所见,这些实际上位于我输入的指定日期/时间之下。 I assume that this has something to do with the formatting of the date? 我认为这与日期格式有关吗?

How should my query look to get accurate results? 我的查询应如何获得准确的结果?

If you have saved the data in datetime or timestamp then you are getting the correct result, the hour minute and second format is H:i:s ie 24 hours format. 如果您已将数据保存为datetime timestamptimestamp那么您将获得正确的结果,小时,分钟和秒格式为H:i:s即24小时格式。

So in the comparison 所以在比较

created_at > '2015-04-26 02:04:24'

2015-04-26 02:04:24 means 2 AM + and the results you are getting are all greater than that 2015-04-26 02:04:24表示2 AM + ,而您获得的结果均大于

10 AM, 12 PM and so 10 AM, 12 PM

If you are looking to find greater than 2 PM then you need 如果您要查找2 PM则需要

created_at > '2015-04-26 14:04:24'

Ok, so thanks to the commenters I have figured out what was going on, I didn't actually think to check the actual time value, but in my PHP script I was converting the timestamp to h:m:s this should have been H:m:s (24hr) and it is now producing the correct results. 好的,感谢评论者,我弄清楚了发生了什么,我实际上并没有考虑检查实际的时间值,但是在我的PHP脚本中,我将时间戳转换为h:m:s这应该是H:m:s (24hr),现在可以产生正确的结果。

Thanks for prompting me to check that, I can miss the simplest things sometimes. 感谢您提示我进行检查,有时我会错过最简单的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM