Python Practice › Basic Programs › Program 33

Get the current date and time

EasyBasic Programs · 33 of 40

Write a Python program to get the current date (and time).

Advertisement
Output
Today: 2026-11-02
Year: 2026 Month: 11 Day: 2
Weekday: Monday

Approach

  1. Use date.today() for the date and datetime.now() for date and time.

Solution

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

More basic programs

← All 40 Basic Programs

Leave a Comment