I have been trying to select items from my database that are between two default dates: now and 60 days ago. However all the queries that I try do not work.
Here is what I have tried:
$Now = date("Y-m-d");
$Before = date("Y-m-d", strtotime("-60 days");
// This is try1
$sql = "SELECT * FROM myTable WHERE myTimestamp BETWEEN " . $Before . " AND " . $Now;
// This is try2
$sql = "SELECT * FROM myTable WHERE myTimestamp >= " . $Before . " AND myTimestamp <= " . $Now;
I am out of guesses of how to do this. I have looked at the other questions that are the same as this one, but none of the solutions presented work.
Please note: these queries do not give an errors. They just don't retrieve anything. I have also used get_defined_vars()
to print the dates onto the page. This is what they show:
[Now] => 2016-01-07
[Before] => 2015-11-08