Python Practice › Basic Programs › Program 21

Print the current date in a format

EasyBasic Programs · 21 of 40

Write a Python program to print the current date in the format “2023 Jan 05” (year, short month name, day) using the datetime module.

Advertisement
Output
2026 Nov 02

Approach

  1. Get today’s date with date.today().
  2. Format it with strftime("%Y %b %d").

Solution

Python
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.

More basic programs

← All 40 Basic Programs

Leave a Comment