Hello!
I have a little problem.
I have a date and a name field in my database's table and I want to list all the names that have been inserted in the last x days.
Example
Name1 2004-04-01
Name2 2004-03-02
Name 3 2003-11-03
And I want for example to list all the names that have been inserted in the last 40 days:
Name1
Name2
Thank You!
Database DATE compare
Moderator: General Moderators
you could try this
Mark
Code: Select all
// what date was it 40 days ago in format yyyy-mm-dd
$fourtyDaysAgo = date('Y-m-d',strtotime(date('Y-m-d').' -40 days'));
// build query
$sql = "SELECT * FROM users WHERE date >= '$fourtyDaysAgo'";