Page 1 of 1

Database DATE compare

Posted: Mon Apr 05, 2004 9:26 am
by gls2ro
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!

Posted: Mon Apr 05, 2004 10:03 am
by JayBird
you could try this

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'";
Mark