I\'m grabbing some information from a database and the record is in an MSSQL DateTime format, when I return it, it shows in my array as follows:
[arrayItem] =>
Try this. It works for me:
$array['arrayItem']->format('Y-m-d H:i:s');
Reference: http://php.net/manual/en/datetime.format.php
echo $array['arrayItem']->format('Y-m-d H:i:s');
Another solution is to loop.
$_date = \DateTime::createFromFormat('D M d Y H:i:s e+', $the_date);
foreach($_dateStart as $row){
echo $row; // returns 2014-06-04 15:00
break; // stops at the first position
}
It is functionality and simple to use.
You can convert date from date object instead of string here is the way how to use:
$obj->arrayItem->format('H:i:s')
$obj->arrayItem->format('Y-m-d')
This worked for me
date('Y-m-d', strtotime($rs->Fields('time')->value)
For Adodb connection on MSSQL Server
If you want to show data in PHP page you just copy and paste in <?php ?>
code :
$serverName = "your_sqlserver";
$username = "your_username";
$password = "your_password";
$database = "your_database";
$connectionInfo = array( "UID"=>$username, "PWD"=>$password, "Database"=>$database, "ReturnDatesAsStrings"=>true);
$connection = sqlsrv_connect($serverName, $connectionInfo);
$result = sqlsrv_query( $connection,"SELECT * from table'");
$msrow = sqlsrv_fetch_array($result);
print_r($msrow['column_name']);