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 changes may need to be made when transitioning code from PHP 4 to PHP 5, specifically related to is_dir() function?
- In cases where server variables like $DOCUMENT_ROOT are missing or not displaying correctly, what are the best practices for troubleshooting and resolving such issues in PHP development?
- What are some best practices for handling complex logical expressions in PHP if statements to ensure code clarity and maintainability?