Formatting date values returned from MYSQL table to more readable format including timeYou can check the date_format tutorial to get value directly from mysql without using PHP side formattingWhen 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. <?
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. |
Related Tutorial |
---|
• Date difference • Year from Date field • PHP Date Format |