fromisoformat() Function Of Datetime.date Class In Python

fromisoformat() constructs a date object from a string containing a date in ISO format i.e., YYYY-MM-DD. The example Python program also prints the type of the object after constructing a date.

Date Updated 12 Jul 2019 1 min read

Function Name

fromisoformat

Function Signature

@classmethod fromisoformat(date_string)

Parameters

date_string – The date string in ISO format – yyyy-mm-dd

Function Overview

  • The class method fromisoformat() from the date class of Python datetime module, constructs a date object from a string containing date in ISO format. i.e., yyyy-mm-dd.

Example

python
# Example Python program that constructs a date object

            # from a string containing a date in ISO format. i.e., YYYY-DD-MM

import datetime

# Birth day of Picaso

            birthday_Picaso = "1881-10-25"

# Construct a datetime.date object

            picasoBirthDate = datetime.date.fromisoformat(birthday_Picaso)

            print("Birth day of Picaso: %s"%picasoBirthDate)

# Print the type

            print(type(picasoBirthDate))

Output

Output
Birth day of Picaso: 1881-10-25

<class 'datetime.date'>