In PHP development, handling dates is a common requirement. The date_format() function allows you to easily format dates into the 'year-month-day' format.
The date_format() function accepts two parameters: a datetime string and a format string. The format characters for year, month, and day are as follows:
$date = '2023-05-18';
// Convert the date to year-month-day format
$formattedDate = date('Y-m-d', strtotime($date));
echo $formattedDate; // Output: 2023-05-18
Using this method, you can easily format any valid date string into a standard year-month-day format, which is useful for consistent date management and display in PHP projects.