🔧 Quick Syntax
SELECT DATE_FORMAT(date_column, 'format_string')
FROM table_name;
This tells SQL:
“Take this date, and show it to me in the format I want.”
Note: This works in MySQL and compatible systems.
🧾 Here’s the Table You’re Working With
Your table is called events
:
id | title | event_date |
---|---|---|
1 | Product Launch | 2025-04-14 |
2 | Demo Day | 2025-05-01 |
3 | Hackathon | 2025-06-21 |
4 | Webinar | 2025-04-28 |
5 | Team Meetup | 2025-04-18 |
✅ Suppose You Want to Format the Date as “April 14, 2025”
SELECT title, DATE_FORMAT(event_date, '%M %d, %Y') AS formatted_date
FROM events;
💡 Output:
Product Launch → April 14, 2025
Demo Day → May 01, 2025
Hackathon → June 21, 2025
Much more human-friendly than raw dates.
✅ Suppose You Want a Short Style: “14-Apr-25”
SELECT title, DATE_FORMAT(event_date, '%d-%b-%y') AS short_date
FROM events;
💡 Output:
Product Launch → 14-Apr-25
Demo Day → 01-May-25
Hackathon → 21-Jun-25
Clean, compact, and perfect for reports or internal tools.
✅ Format Codes You Can Use
Code | Meaning |
---|---|
%Y | Full year (e.g. 2025) |
%y | Two-digit year (e.g. 25) |
%M | Full month name (e.g. April) |
%b | Abbreviated month (e.g. Apr) |
%m | Month as number (01–12) |
%d | Day with leading zero (01–31) |
%e | Day without zero (1–31) |
%W | Weekday name (e.g. Monday) |
%a | Abbr. weekday (e.g. Mon) |
🧃 Recap – What You Learned
DATE_FORMAT()
lets you customize how a date looks- Use format codes like
%M
,%d
,%Y
for full control - It only affects the output — not the stored value
- Perfect for reports, exports, front-end views, and user-friendly logs