PHP + SQL SERVER 2005: correct conversion to date?

Good afternoon.

In a PHP script, I make a request to the SQL server filtered by date:

$start_date = 2011-09-20 00:00:00.000
$now_date = 2011-09-20 17:45:16.999
AND moment >= CAST('$start_date' AS datetime2)
AND moment <= CAST('$now_date' AS datetime2)

But the server does not recognize the string to date conversion: Type date is not a defined system type.

If

AND moment >= CONVERT (datetime, '2011-09-20 00:00:00.000', 21) 
AND moment >= CONVERT (datetime, '2011-09-20 18:10:02.000', 21)

I get nothing in response, i.e. filtering conditions are not met. Tried to use CONVERT(datetime, ‘2011-09-20 18:10:02.000’, 21) again empty in response.

Does not work on SQL Server 2005 Express.

How to correctly convert a string to a date in 2005. On 2008, all the above examples work.


Answer 1, authority 100%

SQL Server Helper – Tips and Tricks – Date Formats