Running php 5.2.5 on Windows Server 2003 (64 bit) and connecting to SQL Server 2008
Having issues getting datetime fields from SQL Server using mssql_query. Any datetime field that I query returns nothing. All other fields in the query are correct, but the datetime fields are blank.
We switched from PEAR DB to mssql_ functions recently and that was the cause of the issue. Switching back to PEAR is not an option.
I found this on php.net mssql_query page and it does work, but I've got hundreds of queries and I was hoping there was a solution that wouldn't require us updating every single query. Anyone have a better solution that would not involve rewriting every query?
"I was tripped up by the fact that mssql_query() returns values for 'datetime' columns in an unusual format. In order to get your values returned in the usual 'YYYY-MM-DD HH:MM:SS' format, you can use the CONVERT function in your query like so:
SELECT CONVERT(varchar, INVOICE_DATE, 121) AS INVOICE_DATE ...
where 'INVOICE_DATE' is the name of the 'datetime' column."