Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 316
not_shitashi Avatar asked Oct 15 '25 09:10

not_shitashi


1 Answers

$string=$row["date_column"]->format('Y-m-d H:i:s')
like image 99
foxiris Avatar answered Oct 16 '25 22:10

foxiris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!