
今回はプログラムを実行した時に実行した日付の月初めの日付を取得するコードを備忘録として残します。
1 2 3 4 5 6 7 8 |
import datetime dt = datetime.datetime.now() d = datetime.date(dt.year,dt.month, dt.day) print(d.replace(day=1)) #2020-12-01 |
datetimeオブジェクトのコンストラクタ
datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
year, month, dayが必須となります。