Python datetime.datetime.month Attribute
Vaibhav Vaibhav
Jan 30, 2023
Python
Python DateTime
-
Syntax of Python
datetime.datetime.monthAttribute -
Example Codes: Use
datetime.datetime.monthAttribute in Python
The datetime is a built-in library in Python that offers several high-level classes to represent quantities such as dates (datetime.date), date and time combined (datetime.datetime), and time zones (tzinfo).
This article will briefly discuss Python’s datetime.datetime.month Attribute.
Syntax of Python datetime.datetime.month Attribute
<datetime object>.month
Parameters
Since it is an attribute of a class, it does not have any parameters.
Returns
Since it is an attribute of a class, it does not return anything. It stores the month number between 1 and 12.
Example Codes: Use datetime.datetime.monthAttribute in Python
import datetime
dt = datetime.datetime.now()
print("DateTime:", dt)
print("Month:", dt.month)
Output:
DateTime: 2022-08-24 14:39:44.782452
Month: 8
The Python code above first creates a datetime object using the now() method and then prints the datetime object and the value of the month attribute.
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Vaibhav Vaibhav
