1

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.

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

I gave up on finding functions or parameters to force the PHP Sql Driver to return DateTime objects, so I wrote this helper function: if(gettype($this->timestamp) == 'string') return DateTime::createFromFormat('M j Y h:i:s:uA', $this->timestamp);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.