'How to get(extract) year, month or day from datetime.datetime(2021, 1, 25, 21, 20, 46) format? Python

could you please advice on this one?

How to get(extract) year, month or day from datetime.datetime(2021, 1, 25, 21, 20, 46) format? For ex from the date (2021, 1, 25, 21, 20, 46) I want to extract month - 1. How can I do that? I tried month() method but doesnt work : TypeError: 'int' object is not callable

import datetime x= datetime.datetime(2021, 1, 25, 21, 20, 46) print(x.month()) TypeError: 'int' object is not callable

Thanks :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source