I want to create a check for a parameter of a function to have only datetime arguments as strings!
So i was taking a string value and converting it to datetime.date object.. and check using isinstance or type is datetime.date..But it is not returning True as expected.. Can someone please help me in identifying the issue ?
>Solution :
date_format = "%Y%m"
date_string = "202110"
import datetime
date_object = datetime.datetime.strptime(date_string,date_format).date()
print(date_object)
print(type(date_object))
print(type(date_object) is (datetime.date))
Importing datetime module this way solves the problem. Actually from datetime import datetime is ambiguous for python as it gets confused whether you are referring to the datetime module or the function. Importing it in the above way removes ambiguity. You can read more about it on a similar question posted at stackoverflow LINK