Python datetime.datetime.month Attribute

Vaibhav Vaibhav Jan 30, 2023
  1. Syntax of Python datetime.datetime.month Attribute
  2. Example Codes: Use datetime.datetime.monthAttribute in Python
Python datetime.datetime.month Attribute

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.

Vaibhav Vaibhav avatar Vaibhav Vaibhav avatar

Vaibhav is an artificial intelligence and cloud computing stan. He likes to build end-to-end full-stack web and mobile applications. Besides computer science and technology, he loves playing cricket and badminton, going on bike rides, and doodling.

Related Article - Python DateTime