Reputation: 802
The pdo_sqlsrv PHP driver always returns a datetime column from MS SQL as a String. I want it to be an object (just like w/ the official Windows MSSQL driver for PHP)
I explicitly set ReturnDatesAsStrings to false in the connect parameters for the DB connection, and tried setting the mssql.datetimeconvert to both On and Off in my php.ini, but none of that yields a datetime object in PHP as a result. Only Strings: Feb 17 2016 09:48:56:213AM
I retrieve the data via sqlsrv_fetch_object(sqlsrv_query($connection, $querystr))
Through Google, I can only find people having the opposite problem (wanting to return dates as strings, not objects)... But I want the Linux version to be compatible to the Windows version in that regard.
Upvotes: 1
Views: 397
Reputation: 11
I've found no low-level solution, other than creating a function to ensure the date is converted to an object:
Function cdate($dat) {
return (gettype($dat)=="string" ? new DateTime($dat) : $dat);
}
Upvotes: 1