Python Datetime Methods

Beginner
6 min read
Updated: Nov 2026
29 method guides
Method index

About This Index

This page is the Python Datetime Methods index for the tutorial track. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example uses fixed dates and fixed UTC offsets, so the output you see is the output you get, whatever your clock or time zone says.

Learn naive vs aware objects and format codes on the Datetime hub. Use this page when you need a specific method such as strftime(), fromisoformat(), or astimezone().

Five classes, one module.

The Class column tells you where a method lives: datetime.datetime (date plus time), datetime.date (calendar day), datetime.time (clock time), datetime.timedelta (duration), or datetime.tzinfo (time zone rules). utcnow() and utcfromtimestamp() are deprecated since Python 3.12.

How to Call a Datetime Method

Classmethods are called on the class and build a new object; instance methods are called on an object you already have:

Python
from datetime import datetime, timedelta, timezone

moment = datetime(2024, 3, 15, 10, 30)               # constructor
parsed = datetime.strptime("15/03/2024", "%d/%m/%Y")  # classmethod
print(moment.strftime("%d %b %Y"))                   # 15 Mar 2024
print(moment.weekday())                              # 4 (Friday)
print(parsed.date())                                 # 2024-03-15
print(timedelta(hours=2).total_seconds())            # 7200.0
print(moment.replace(tzinfo=timezone.utc).isoformat())

Python Datetime Methods Table

All method guides in this Python tutorial series (29 tutorials), grouped by purpose.

Create date and datetime objects

10 methods

Class methods that build a new object: the current moment, an epoch timestamp, a day number, an ISO 8601 string, an ISO week, a custom-format string, or a date plus a time.

MethodClassDescriptionTutorial
now()datetime.datetimeClassmethod: the current date and time, naive local or aware with tz.Try it
today()datetime.date (also datetime)Classmethod: the current local date (date.today) or naive local date and time.Try it
utcnow()datetime.datetimeDeprecated classmethod: current UTC time as a naive datetime; use now(timezone.utc).Try it
fromtimestamp()datetime.datetime (also date)Classmethod: turn a POSIX timestamp (seconds since 1970 UTC) into a datetime.Try it
utcfromtimestamp()datetime.datetimeDeprecated classmethod: timestamp to naive UTC datetime; use fromtimestamp(ts, tz=timezone.utc).Try it
fromordinal()datetime.date (also datetime)Classmethod: build a date from a proleptic Gregorian day number (1 = 0001-01-01).Try it
fromisoformat()datetime.datetime (also date, time)Classmethod: parse ISO 8601 text such as 2024-03-15T10:30:00+05:30.Try it
fromisocalendar()datetime.date (also datetime)Classmethod: build a date from an ISO year, week number, and weekday.Try it
strptime()datetime.datetimeClassmethod: parse a string into a datetime using format codes like %Y-%m-%d.Try it
combine()datetime.datetimeClassmethod: join a date and a time into one datetime, with an optional tzinfo.Try it

Format and convert

10 methods

Turn a date or datetime into text, a time tuple, ISO week numbers, a weekday number, a day number, or a POSIX timestamp.

MethodClassDescriptionTutorial
strftime()datetime.datetime (also date, time)Format a date or datetime as text using % codes such as %Y-%m-%d %H:%M.Try it
isoformat()datetime.datetime (also date, time)Return ISO 8601 text such as 2024-03-15T10:30:45+05:30, with sep and timespec options.Try it
ctime()datetime.datetime (also date)Return a fixed C-style string such as 'Fri Mar 15 10:30:45 2024'.Try it
timetuple()datetime.datetime (also date)Return a time.struct_time with year, day of year, weekday, and DST flag.Try it
utctimetuple()datetime.datetimeReturn a struct_time in UTC: aware values are converted, the DST flag is 0.Try it
isocalendar()datetime.date (also datetime)Return the ISO 8601 (year, week, weekday) for a date.Try it
isoweekday()datetime.date (also datetime)Return the day of the week as 1 (Monday) to 7 (Sunday).Try it
weekday()datetime.date (also datetime)Return the day of the week as 0 (Monday) to 6 (Sunday).Try it
toordinal()datetime.date (also datetime)Return the proleptic Gregorian day number, where 0001-01-01 is day 1.Try it
timestamp()datetime.datetimeReturn the POSIX timestamp (seconds since 1970 UTC) as a float.Try it

Extract and replace parts

4 methods

Split a datetime into its date and time parts, keep or drop the time zone, and build a copy with some fields changed.

MethodClassDescriptionTutorial
date()datetime.datetimeReturn the date part of a datetime as a date object.Try it
time()datetime.datetimeReturn the clock part of a datetime as a naive time object.Try it
timetz()datetime.datetimeReturn the clock part of a datetime as a time object that keeps its tzinfo.Try it
replace()datetime.datetime (also date, time)Return a copy with some fields changed, such as year, hour, or tzinfo.Try it

Time zones and offsets

4 methods

Convert an aware datetime to another zone and ask its tzinfo for the UTC offset, the daylight saving adjustment, and the zone name.

MethodClassDescriptionTutorial
astimezone()datetime.datetimeConvert an aware datetime to another time zone, keeping the same instant.Try it
utcoffset()datetime.datetime (also time, tzinfo)Return the offset from UTC as a timedelta, or None for naive values.Try it
dst()datetime.datetime (also time, tzinfo)Return the daylight saving adjustment as a timedelta, or None.Try it
tzname()datetime.datetime (also time, tzinfo)Return the time zone name, such as 'UTC' or 'UTC+05:30', or None.Try it

Durations

1 method

Work with timedelta objects, the result of subtracting two dates or datetimes.

MethodClassDescriptionTutorial
total_seconds()datetime.timedeltaReturn the whole length of a timedelta in seconds, as a float.Try it

Frequently Asked Questions

They are the methods of the classes in the datetime module: date, time, datetime, timedelta, and tzinfo. Some are classmethods that create objects, such as datetime.now() or datetime.strptime(); others are called on an existing object, such as moment.strftime("%Y-%m-%d").
This index lists 29 guides, from astimezone() to weekday(), grouped into constructors, formatting and conversion, extracting parts, time zones, and durations.
The Class column shows it. Most methods live on datetime.datetime; many also exist on datetime.date, and utcoffset(), dst(), and tzname() also exist on datetime.time and come from a tzinfo object. total_seconds() belongs to datetime.timedelta.
No. date, time, datetime, and timedelta objects are immutable. Methods such as replace() and astimezone() return a new object, so assign the result to a variable.
Read the Python Datetime hub first for naive vs aware objects and format codes. Then open now(), strftime(), strptime(), isoformat(), and astimezone() from the tables below.

Start with astimezone()

Open the first guide in the list and work your way through the datetime methods.

astimezone() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful