Link to home
Start Free TrialLog in
Avatar of pda4me
pda4me

asked on

Dynamic Date select using PHP and MySQL

I have the following MySQL query in PHP:

$query = @mysql_query("SELECT * FROM RESI WHERE CITY='City1' OR CITY='City2' AND EntryDate='2006-04-10 00:00:00' ORDER BY EntryDate DESC LIMIT 0,10");

Open in new window


How do I alter this code to use the EntryDate column to select from the past 7 days based on the current date this query is run?
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Try this:

$query = @mysql_query("SELECT * FROM RESI WHERE CITY='City1' OR CITY='City2' AND EntryDate BETWEEN NOW() - 7  AND NOW() ORDER BY EntryDate DESC LIMIT 0,10");
Avatar of pda4me
pda4me

ASKER

blank results...are we missing a ' or something?
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pda4me

ASKER

FYI, EntryDate is a datetime field, not sure if that matters?
We cross-posted... Did you see my second suggestion?
Avatar of pda4me

ASKER

That is great, thanks for the help!
Glad to help :)