Trouble with comparing dates to a database

Hi folks,

I am having serious trouble comparing dates to entries in the database. Here is my following code:

$newdate2 = date(“Y-m-d H:i:s”, mktime(date(“H”), date(“i”), date(“s”), date(“m”), date(“d”)-1, date(“Y”)));

$query = “select count (*) as counter FROM Orders WHERE UNIX_TIMESTAMP(OrderDate) > $newdate2”;
$result = mysql_query($query);
$row = mysql_fetch_array($result);

The page gives me an error around where the date is being compared.

OrderDate is a datetime variable with yyyy-mm-dd hh:mm:ss format.
I have tried the code without the UNIX_TIMESTAMP and it still doesn’t work.

Thanks in advance,

  • Michael

What’s the error look like?

The error that I receive is as follows:

ERROR: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(*) as counter FROM Orders WHERE OrderDate > 2007-05-

  • Michael

Get rid of the space between count and (*).

Thanks,

I hate it when it’s something so obvious that you just keep missing.

  • Michael
Sponsor our Newsletter | Privacy Policy | Terms of Service