I want to SELECT all the rows from the table that correspond to a specific date.
I have the timestamp stored in the pattern 2010-08-18 04:43:00.
How can I query the table if I want to select all the rows that fall within a day’s time?
One way I can think of is get the day’s timestamp, convert it into Unix timestamp and then query the table. But that sounds like a lot of work. Is there any easier alternative?
Thanks a lot in advance.
The approach outlined by Michael works, but is string-based and as such not as efficient as an integer-based search.
I don’t really see a problem in creating two UNIX timestamps, one for 00:00:00 and one for 23:59:59, and checking to see if you fall within that time. (Be sure to actually calculate these two separate values to make sure you account for daylight savings time).
You can even use MySQL to get those values if you really don’t want to do it yourself (
SELECT UNIX_TIMESTAMP("$Timestamp 00:00:00"), UNIX_TIMESTAMP("$Timestamp 23:59:59")), and then use those two values.If you have a small dataset, Michael’s approach above is fine.