Type Object 'Datetime.Datetime' Has No Attribute 'Datetime'

type object 'datetime.datetime' has no attribute 'datetime'

For python 3.3

from datetime import datetime, timedelta
futuredate = datetime.now() + timedelta(days=10)

type object 'datetime.datetime' has no attribute 'fromisoformat'

The issue here is actually that fromisoformat is not available in Python versions older than 3.7, you can see that clearly stated in the documenation here.

Return a date corresponding to a date_string given in the format YYYY-MM-DD:
>>>

>>> from datetime import date
>>> date.fromisoformat('2019-12-04')
datetime.date(2019, 12, 4)

This is the inverse of date.isoformat(). It only supports the format YYYY-MM-DD.

New in version 3.7.

How to solve type object 'datetime.datetime' has no attribute 'timedelta' when creating a new date?

You've imported the wrong thing; you've done from datetime import datetime so that datetime now refers to the class, not the containing module.

Either do:

import datetime
...article.created_on + datetime.timedelta(...)

or

from datetime import datetime, timedelta
...article.created_on + timedelta(...)


Related Topics



Leave a reply



Submit