how to retrieve a sql datetime object with a php $row?

For instance:

$sql = "SELECT * FROM db";
$query = sqlsrv_query($conn, $sql);

while($row = sqlsrv_fetch_array($query)){
    echo "$row[date_column]";

will crash

Most of the answers I've found are assuming you want to order your query by a datetime, but I just want to turn the datetime object into a string after I have all the rows.

I don't really understand how to use the php date() function, I've tried:

echo date("m/d/Y",$row[date_column]); //prints nothing


$string=$row["date_column"]->format('Y-m-d H:i:s')

First of all, if "date_column" is the column name, it should be in quotes, like this:

echo $row["date_column"];

Secondly, PHP has a built-in function to turn MYSQL datetime into a unix timestamp, which PHP date() can use. Try this:

echo date("m/d/Y", strtotime($row["date_column"]));


    $logdate=date_format($row[4],"Y-m-d H:i:s");

here, $row[4] contains the date object. This would surely help.

Need Your Help

How javascript "this" handles multiple selector returns from jquery?

javascript jquery

I was making a menu today, and I stumbled on this curious case, with the following HTML:

Grabbing a user_group in MODx

user-controls content-management-system login modx

Currently I have a Client login area. In this login area I was going to create a snippet that shows certain information for 'Admin' users.