+91 81900 98289

Python Dates

This Python Dates lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

datetime.date is a calendar day. datetime.now is a date and a time. Formatting uses strftime codes such as %Y and %m.

Store dates as date objects, not as hand-built strings, when you need to compare or add days.

Example 1: Start here

Month codes are case sensitive. %m is the month number. %M is minutes.

from datetime import date # load a tool that comes with Python today = date(2026, 10, 24) # a calendar date print(today.strftime("%d %b %Y"))

Example 2: Today

date.today returns the current date.

from datetime import date # load a tool that comes with Python print(date.today())

Example 3: Build a date

The order is year, month, day.

from datetime import date # load a tool that comes with Python print(date(2026, 10, 24))

Example 4: Format it

strftime turns the date into text using the pattern you give it.

from datetime import date # load a tool that comes with Python print(date(2026, 10, 24).strftime("%d %b %Y"))
Month codes are case sensitive. %m is the month number. %M is minutes.
Call Now 81900 98289