0

I have an SQL database table which contains a column which holds data of datetime format. Now, after getting the values of this row, I need to convert the datettime to a readable string, but I'm unable to do this. Here's the code I'm using:

$result = mysqli_query($handle, "SELECT * FROM $dbTable WHERE id=$id");

while($curr = mysqli_fetch_array($result))
{
    // CONVERT $curr['datetimefield'] TO STRING
    // echo $strong-format-of-datetime;
}

The conversion part is what I'm stuck at. If anybody could help with this, I'd be really grateful.

Thank You.

Akshay Kashyap
  • 49
  • 1
  • 2
  • 4

2 Answers2

4

You can change format what you want: Y-m-d H:i:s

$date = strtotime($curr['datetimefield']);
echo date('Y-m-d H:i:s', $date);
Bora
  • 10,529
  • 5
  • 43
  • 73
-1

Also you can convert date while SQL query: STR_TO_DATE(date,'%d.%m.%Y')

user2443795
  • 144
  • 7