• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

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?
0
pda4me
Asked:
pda4me
  • 4
  • 3
1 Solution
 
mbizupCommented:
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");
0
 
pda4meAuthor Commented:
blank results...are we missing a ' or something?
0
 
mbizupCommented:
Or this:

$query = @mysql_query("SELECT * FROM RESI WHERE CITY='City1' OR CITY='City2' AND datediff(NOW(),EntryDate) > 7  ORDER BY EntryDate DESC LIMIT 0,10");
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
pda4meAuthor Commented:
FYI, EntryDate is a datetime field, not sure if that matters?
0
 
mbizupCommented:
We cross-posted... Did you see my second suggestion?
0
 
pda4meAuthor Commented:
That is great, thanks for the help!
0
 
mbizupCommented:
Glad to help :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now