What are some common methods for formatting date values in PHP when retrieving data from a database?
When retrieving date values from a database in PHP, they are often in a standard format such as 'Y-m-d H:i:s'. However, you may want to format these dates differently for display purposes, such as 'd-m-Y' or 'M j, Y'. To do this, you can use the date() function in PHP to format the date values as needed.
// Retrieve date value from database
$dateFromDatabase = '2022-01-15 14:30:00';
// Format date value for display
$formattedDate = date('d-m-Y', strtotime($dateFromDatabase));
echo $formattedDate; // Output: 15-01-2022
Keywords
Related Questions
- How can one effectively manage a PHP project that involves object-oriented programming, JavaScript, jQuery, and Ajax?
- How can the PHP function imagerotate be utilized to correct image orientation based on EXIF data?
- How can one ensure that a database is overwritten during import rather than creating a new one in PHP?