I have a DB created by a third party vendor that I’m now writing a new UI for.
The DB stores event start times as unix timestamps (in GMT). What I need to do is query this for a one day range. So presumably I simply need to do a:
SELECT * WHERE start > $last_night_at_midnight AND start < $tonight_at_midnight
The problem I’m running into is a simple way to combine the date/time functions in PHP to create those variables. It feels like everything I’m doing is way too complicated for such a simple procedure.
Does anyone have a simple solution to this?
Cheers
This is a really backwards way of doing it, but if you need to be able to do various date ranges, not just today or one day, you could combine the odd time/date features of both languages and go with:
using the DATE() in the query ensures that the sql won’t bother looking at the time part of the data, and using FROM_UNIXTIME for all three means that the sql server is consistent in how it derives the dates.
My favorite way of getting a date range for just today is:
strtotime is actually better, I’ve found, then adding 86400 or anything like that, because strtotime handles DST better. Found that out last week.