Python Practice › Basic Programs › Program 33
Get the current date and time
Write a Python program to get the current date (and time).
Output
Today: 2026-11-02 Year: 2026 Month: 11 Day: 2 Weekday: Monday
Approach
- Use
date.today()for the date anddatetime.now()for date and time.
Solution
from datetime import date, datetime print("Today:", date.today())now = datetime.now()print("Year:", now.year, "Month:", now.month, "Day:", now.day)print("Weekday:", now.strftime("%A"))Output
Today: 2026-11-02 Year: 2026 Month: 11 Day: 2 Weekday: Monday
Line by line
Line 3
Prints the date in ISO format, year-month-day.
Line 5
A datetime exposes each part as an attribute.
Line 6
%A gives the full weekday name.
Note
The output shows the date on which this page was built.
Learn the concept
New to this topic? Read the lesson, then come back.