简体   繁体   中英

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.

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

10 AM, 12 PM and so

If you are looking to find greater than 2 PM then you need

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.

Thanks for prompting me to check that, I can miss the simplest things sometimes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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