TypeError: descriptor ‘date’ for ‘datetime.datetime’ objects doesn’t apply to a ‘int’ object

We Are Going To Discuss About TypeError: descriptor ‘date’ for ‘datetime.datetime’ objects doesn’t apply to a ‘int’ object. So lets Start this Python Article.

TypeError: descriptor ‘date’ for ‘datetime.datetime’ objects doesn’t apply to a ‘int’ object

  1. How to solve TypeError: descriptor 'date' for 'datetime.datetime' objects doesn't apply to a 'int' object

    Solution:
    import datetime my_date = datetime.date(2021, 3, 2)
    or
    from datetime import date my_date = date(2021, 3, 2)
    Why?
    The issue is that datetime.datetime.date() is a method on a datetime.datetime object. We were confusing the datetime module with the datetime.datetime class.
    What we're really looking for is the datetime.date() constructor.

  2. TypeError: descriptor 'date' for 'datetime.datetime' objects doesn't apply to a 'int' object

    Solution:
    import datetime my_date = datetime.date(2021, 3, 2)
    or
    from datetime import date my_date = date(2021, 3, 2)
    Why?
    The issue is that datetime.datetime.date() is a method on a datetime.datetime object. We were confusing the datetime module with the datetime.datetime class.
    What we're really looking for is the datetime.date() constructor.

Solution 1

Solution:

import datetime
my_date = datetime.date(2021, 3, 2)

or

from datetime import date
my_date = date(2021, 3, 2)

Why?

The issue is that datetime.datetime.date() is a method on a datetime.datetime object. We were confusing the datetime module with the datetime.datetime class.

What we’re really looking for is the datetime.date() constructor.

Original Author edited Jun 9, 2021 at 3:58 Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment