I have a field in my table called date and it stores via the NOW() function the date the entry was added.
I need to query the database to find entries within the last 30 days only.
Is this possible in a single query?
I have a field in my table called date and it stores via the NOW() function the date the entry was added.
I need to query the database to find entries within the last 30 days only.
Is this possible in a single query?
Sure. Create a time window and you can limit by that date
$time = time() - (86400 * 30); // 86400 seconds in one day
$sql = 'SELECT * FROM table WHERE datefield > "' . date('Y-m-d H:i:s', $time) . '"';
That should yield you records within the last 30 days