The Wayback Machine - https://web.archive.org/web/20240206215353/https://www.geeksforgeeks.org/fromisoformat-function-of-datetime-date-class-in-python/
Open In App
Related Articles

fromisoformat() Function Of Datetime.date Class In Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The fromisoformat() function is used to constructs a date object from a specified string that contains a date in ISO format. i.e., yyyy-mm-dd.

Syntax: @classmethod fromisoformat(date_string)

Parameters: This function accepts a parameter which is illustrated below:

  • date_string: This is the specified ISO format i.e., yyyy-mm-dd date string whose date object is going to be constructed.

Return values: This function returns a date object constructed from the specified ISO format date string.

Example 1: Getting a date object from a specified string that contains date in ISO format. i.e., yyyy-mm-dd

Python3




# Python3.7 code for Getting
# a date object from a specified
# string that contains date in
# ISO format. i.e., yyyy-mm-dd
  
# Importing datetime module
import datetime
  
# Initializing a date
Date = "2012-10-12";
  
# Calling fromisoformat() function to
# construct a datetime.date object 
New_date = datetime.date.fromisoformat(Date);
  
# Printing the new constructed date object
print("The constructed date object is: %s"%New_date);


Output:

The constructed date object is: 2012-10-12

Example 2: Get the newly created date object for the specified date.

Python3




# Python3.7 code for Getting
# a date object from a specified
# string that contains date in
# ISO format. i.e., yyyy-mm-dd
  
# Importing datetime module
from datetime import date
  
# Calling the fromisoformat() function
# to Print the new created date object
# for the specified date in
# ISO format of 2020-10-09
print(date.fromisoformat('2020-10-09'))


Output:

2020-10-09

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


Last Updated : 23 Aug, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials