🧾 DATE_FORMAT() – Format a Date into a Custom Style

🔧 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
1Product Launch2025-04-14
2Demo Day2025-05-01
3Hackathon2025-06-21
4Webinar2025-04-28
5Team Meetup2025-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

CodeMeaning
%YFull year (e.g. 2025)
%yTwo-digit year (e.g. 25)
%MFull month name (e.g. April)
%bAbbreviated month (e.g. Apr)
%mMonth as number (01–12)
%dDay with leading zero (01–31)
%eDay without zero (1–31)
%WWeekday name (e.g. Monday)
%aAbbr. 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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top