LoginSignup
4
4

More than 5 years have passed since last update.

Pythonで月末日を求める

Posted at

予算管理のレポートだとかで、月末日を自動算出したい場合があります。
そんなときの月末日の求め方です。

すごく単純です。relativedeltaを利用するだけだったりします。

from datetime import datetime
from dateutil.relativedelta import relativedelta

print((datetime.today().replace(day=1) + relativedelta(months=1, days=-1)).date())

シンプルですね。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4