Basically I’m looking to convert a Timestamp field from the: 2012-03-14 23:14:58 format to the (more readable) 23:14 pm March 15, 2012
I’ve been through this tutorial, however I couldn’t really get my head around it. I’ve included my current PHP script which I’m using to parse the MySQL database data to an Android application.
<?php
$con = mysql_connect("*******", "*******", "*******");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bluebase", $con);
$q=mysql_query("SELECT * from Comments where Category = 'General' ORDER BY Timestamp DESC");
while($e=mysql_fetch_assoc($q))
$output['General'][]=$e;
print(json_encode($output));
mysql_close();
?>
There’s a couple paths you can take. What I always do is store the time in the database as a Unix Timestamp, since it’s simple to convert from there. If you already have data in your database and it’s too late to change it (or you have other reasons for having the date in that format in the database), then you’ll need to convert your time into a unix timestamp so it’s usable in the PHP date function:
… that overwrites the Timestamp field with your reformatted timestamp.