どうも、ちょげ(@chogetarou)です。
DateTimeで今月の月を取得する方法を紹介します。
方法

DateTimeで今月の月を取得するには、now()とmonthを使います。
まず、datetimeからnow()を呼び出します。
そして、now()の結果のmonthプロパティにアクセスします。
current_month = datetime.now().month
datetime.now().monthは、今月の月を返します。
使用例
from datetime import datetime
current_day = datetime.now()
current_month = datetime.now().month
print(current_day) #2022-06-29 08:04:17.412943
print(current_month) #6
print(type(current_month)) #<class 'int'>
コメント