I want to select records from my table which have a date which is older than 200 days.
The following code calculates that date and displays it on the page as '2011-08-10':

$todayDate = date("Y-m-d");// current date
echo "Today: ".$todayDate."<br>";
//Subtract 200 days from today
$rptdate = strtotime(date("Y-m-d", strtotime($todayDate)) . " -200 day");
echo "200 days ago:";
print $rptdate;

When I put hard-code '2011-08-10' as a criteria for my query, it works fine. When I put $rptdate in it only shows me records which have no date at all.

What am I missing?

Recommended Answers

All 2 Replies

I solved my own problem. I was making it more difficult than it needed to be.

I needed to add apostrophes before and after the variable in the query, like:

Select * from phones where updatedate > '$rptdate'

Mark this thread as solved if your problem solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.