What is date.isoformat() in Python?

Overview

This isoformat() function belongs to the datetime module in Python. It converts the Date object value into a string in ISO format. It follows the ISO 8601, or YYYY-MM-DD, format. It is an inverse function of date.fromisoformat().

Note: datetime module in Python is used to manipulate date and time.

Syntax

date.isoformat()

Parameters

This function does not take any argument value.

Return value

This method will return a string containing the date in ISO 8601 format.

Example

In the example below, we are creating an object today_date which will contain today’s date.

In line 6 of the code below, we convert the today_date object to the ISO 8601 string format:

# Load date class from datetime module
from datetime import date
# using isoformat() method
today_date= date.today()
# convert date to string format
date_str = today_date.isoformat()
# string output
print(date_str)

Free Resources