Get the current date and time

from datetime import datetime

now = datetime.now()
print(now)   # 2026-06-30 14:05:09.123456

datetime.now() reads your system clock and returns a full timestamp down to the microsecond.

Get just today’s date

from datetime import date

today = date.today()
print(today)   # 2026-06-30

When you only need the calendar date, date.today() skips the time portion entirely.

Format the date as a readable string

from datetime import datetime

now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M"))   # 2026-06-30 14:05
print(now.strftime("%B %d, %Y"))        # June 30, 2026

strftime turns a datetime into text using format codes such as %Y for the year and %B for the full month name.

Which method should you use?

  • datetime.now() — when you need both date and time.
  • date.today() — when you only need the date.
  • datetime.now(timezone.utc) — when you need a timezone-aware UTC timestamp.
  • Common mistake: mixing up strftime (object to string) and strptime (string to object).

Frequently asked questions

How do I get the time in UTC?

Use datetime.now(timezone.utc) after from datetime import datetime, timezone to get a timezone-aware UTC value.

How do I get only the current time?

Call datetime.now().time(), which returns just the time portion without the date.

Want to handle dates with confidence? Build the basics in our free Python course.