sqlsrv date time converstion

May 30th, 2011 § 0 comments

The PHP Sqlsrv driver for the Sql server 2008 will return dateTime as an Object by default.If you need to use it in PHP then you need to convert into string. The new sqlsrv driver is blessed with the option to convert dateTime to string. You just need to set “ReturnDatesAsStrings” option as TRUE.

$host = "192.168.1.1";

$connectionInfo = array(
"UID" => "db_user",
 "PWD" => "db_password",
 "Database" => "db_sample",
"ReturnDatesAsStrings" =>1
);

sqlsrv_connect($host, $connectionInfo);

Thatz it you have done it. Now the sqlsrv driver for PHP will return all the datetime fields as string.

Revath S Kumar [RSK]

- Rubyist / JavaScripter - Yeoman Team member - Open source enthusiast - Blogger @ PHPRepo and http://blog.revathskumar.com - Coder @ Whatznear - Google fanboy - jQuery lover

More Posts - Website - Twitter - Facebook - LinkedIn - Pinterest - Google Plus - YouTube