spike232 Posted April 15, 2003 Share Posted April 15, 2003 i have a php news board, the entries are read from a mysql db, each entrie has the date it was added, how can i filter it so i only select the ones from the last 30days ?? Link to comment Share on other sites More sharing options...
0 Quboid Posted April 15, 2003 Share Posted April 15, 2003 How do you store the date posted? I'd usually use a timestamp (an integer giving the number of seconds after 00:00 1st Jan 1970), rather than MySQL's fiddly time data types. If you do this, then your query will be something like $query = "SELECT * FROM news WHERE timePosted >= " . (time() - (60*60*24*30)); That will select all fields from the table news where the timePosted (the timestamp) is more than or equal to the current date/time's timestamp minus 30 days (60 seconds * 60 minutes * 24 hours * 30 days). Link to comment Share on other sites More sharing options...
0 spike232 Posted April 15, 2003 Author Share Posted April 15, 2003 thanks, that works great. one more thing, the date field in the mysql db was set to date, however when i changed it to timestamp it would not accept timestamps... so i set it to int to get it to work. should timestamp have worked?? or is int ok? :unsure: Link to comment Share on other sites More sharing options...
0 Quboid Posted April 15, 2003 Share Posted April 15, 2003 Shoulda said... The MySQL timestamp column type isn't the same sort of timestamp that I mentioned. Their's is a (by default 14 character long) number on the format YYYYMMDDHHMMSS so now would be 20030415180042. I meant a timestamp which is just the number of seconds - for this, I use an unsigned int as you found out. Link to comment Share on other sites More sharing options...
Question
spike232
i have a php news board, the entries are read from a mysql db, each entrie has the date it was added, how can i filter it so i only select the ones from the last 30days ??
Link to comment
Share on other sites
3 answers to this question
Recommended Posts