Python Practice › Basic Programs › Program 21
Print the current date in a format
Write a Python program to print the current date in the format “2023 Jan 05” (year, short month name, day) using the datetime module.
Output
2026 Nov 02
Approach
- Get today’s date with
date.today(). - Format it with
strftime("%Y %b %d").
Solution
from datetime import date today = date.today()print(today.strftime("%Y %b %d"))Output
2026 Nov 02
Line by line
Line 3
date.today() reads the date from your computer’s clock.
Line 4
%Y is the 4-digit year, %b the short month name and %d the 2-digit day.
Note
The output shows the date on which this page was built. Press Try it and Run to see today’s date.
Learn the concept
New to this topic? Read the lesson, then come back.