Formatting date values returned from MYSQL table to more readable format including time
When we receive date value or date and time value from mysql table, we need to convert them in more readable format based on our requirement. We will use here two PHP functions. The function strtotime() will convert the returned value in mysql date and time format to timestamp. Then we will apply date() function to convert them into our readable format. Here in our example we will keep two fields in the table, one with one DATE field and the other one with DATETIME field. Before this you can read mysql select query on how to get data from a table.
<?Php
$qt=mysql_query("select * from
dt_tb");
//Now let us display the data
while($nt=mysql_fetch_array($qt)){
echo "$nt[id],".date("d-m-Y : G-i",strtotime($nt[dt])).",$nt[dt2] ";
echo "<br>";
}
?>
This is how the formatting done using strtotime() and date() functions. You can change the date() function formatting based on your requirements. The output of the above script is here.