Complete the code to format the date as 'Year-Month-Day'.
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date FROM orders;
The format string '%Y-%m-%d' outputs the date as Year-Month-Day, which is the desired format.
Complete the code to display the date as 'Month name Day, Year' (e.g., June 15, 2024).
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date FROM orders;
The format string '%M %e, %Y' outputs the full month name, day of the month without leading zero, and full year, matching the desired format.
Fix the error in the code to correctly format the date as 'Day/Month/Year'.
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date FROM orders;
The correct format for 'Day/Month/Year' is '%d/%m/%Y'. This places day first, then month, then year separated by slashes.
Fill both blanks to format the date as 'Hour:Minute AM/PM' (e.g., 03:45 PM).
SELECT DATE_FORMAT(order_time, '[1]:[2] %p') AS formatted_time FROM orders;
%h gives the hour in 12-hour format with leading zero, and %i gives minutes with leading zero. %p adds AM or PM.
Fill all three blanks to format the date as 'Weekday, Month Day, Year' (e.g., Monday, June 15, 2024).
SELECT DATE_FORMAT(order_date, '[1], [2] [3], %Y') AS formatted_date FROM orders;
%W gives the full weekday name, %M the full month name, and %e the day of the month without leading zero, matching the desired format.