I want to output the beginning of the next month with Python

When I searched, only the second pattern was caught, and there was another solution, so I made a note.

Use datetime and calendar

python


import datetime
import calendar

dt = datetime.datetime.today()
max_day = calendar.monthrange(dt.year, dt.month)[1]
nm = datetime.date(dt.year, dt.month, max_day) + datetime.timedelta(days=1)

Use datetime and dateutil relativedelta

python


import datetime
from dateutil.relativedelta import relativedelta

dt = datetime.datetime.today()
nm = dt + relativedelta(months=1)

Recommended Posts

I want to output the beginning of the next month with Python
I want to inherit to the back with python dataclass
I want to debug with Python
I tried to find the entropy of the image with python
I want to specify another version of Python with pyvenv
[Python] I want to use the -h option with argparse
I want to know the features of Python and pip
Keras I want to get the output of any layer !!
I want to output to the console coolly
I want to analyze logs with Python
I want to play with aws with python
I want to know the weather with LINE bot feat.Heroku + Python
Output the contents of ~ .xlsx in the folder to HTML with Python
I want to check the position of my face with OpenCV!
I tried to improve the efficiency of daily work with Python
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I want to use MATLAB feval with python
I want to make a game with Python
I tried to output LLVM IR with Python
I want to use Temporary Directory with Python2
#Unresolved I want to compile gobject-introspection with Python3
I want to solve APG4b with Python (Chapter 2)
I want to customize the appearance of zabbix
I want to write to a file with Python
I want to display the progress in Python!
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I tried to get the authentication code of Qiita API with Python.
I want to express my feelings with the lyrics of Mr. Children
I tried to streamline the standard role of new employees with Python
I want to stop the automatic deletion of the tmp area with RHEL7
I tried to get the movie information of TMDb API with Python
Python: I want to measure the processing time of a function neatly
I want to extract an arbitrary URL from the character string of the html source with python
Learn Nim with Python (from the beginning of the year).
I want to grep the execution result of strace
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to handle optimization with python and cplex
I tried to touch the CSV file with Python
I want to send Gmail with Python, but I can't because of an error
[python] option to turn off the output of click.progressbar
I tried to output the rpm list of SSH login destination to an Excel sheet with Python + openpyxl.
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I want to fully understand the basics of Bokeh
I want to work with a robot in python.
I want to add silence to the beginning of a wav file for 1 second
What you want to memorize with the basic "string manipulation" grammar of python
I want to write in Python! (3) Utilize the mock
I want to crop the image along the contour instead of the rectangle [python OpenCV]
I want to AWS Lambda with Python on Mac!
[ML Ops] I want to do multi-project with Python
I tried to solve the problem with Python Vol.1
Note: How to get the last day of the month with python (added the first day of the month)
I want to output while converting the value of the type (e.g. datetime) that is not supported when outputting json with python
I want to use the R dataset in python
I want to run a quantum computer with Python
I want to increase the security of ssh connections
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to summarize the string operations of Python