I have a pretty complex database with loads of different tables for different things, every thing of which has a timestamp (Y-M-D h:m:s format)
Is there a way I can limit my SQL query to just results from a certain timespan, for example a week ago?
If needbe I have a function to convert these timestamps into unix as
sqlToUnix($date); //returns $unixTime
so for example
mysql_query(SELECT id FROM entries WHERE entries.date >= $formattedDateString);
Thanks!
Just a reminder the database dates are of the format: 2009-02-15 08:47:45
That’s totally possible with the BETWEEN-statement (Since MySQL 4.0):
Also, to calculate the timestamp one week before the current date have a look at the MySQL Online Documentation.