How can PHP be used to format the date retrieved from a MySQL database to a specific format, such as DD.MM.YYYY HH:MM?
To format the date retrieved from a MySQL database to a specific format like DD.MM.YYYY HH:MM, you can use the PHP date() function along with strtotime() to convert the date string from the database into the desired format. You can fetch the date from the database, convert it using strtotime(), and then format it using date().
// Assuming $row['date'] contains the date retrieved from MySQL
$dateFromDB = $row['date'];
// Convert the date to the desired format
$formattedDate = date('d.m.Y H:i', strtotime($dateFromDB));
echo $formattedDate;
Keywords
Related Questions
- What are the differences in PHP versions (4/5) that could affect the functionality of a custom template engine?
- How can a PHP script be written to output all entries of locations as links, as described in the thread?
- What are common pitfalls when using PHP to send emails with attachments, as seen in the provided code snippet?