[CENTOS] Get the last day of the specified month

BASH

YEAR=2014
MONTH=12
date -d${MONTH}/01/${YEAR}-1days+1month '+%Y%m%d'

result


20141231

PYTHON

from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
year = 2014
month = 12
print date(year, month , 1) + relativedelta(months=1) + timedelta(days=-1)

result


2014-12-31

Recommended Posts

Get the last day of the specified month
Note: How to get the last day of the month with python (added the first day of the month)
[Python] How to get the first and last days of the month
[Python] Get the last updated date of the website
[Python] Get the day of the week (English & Japanese)
Get last month in python
Get the number of digits
[Python] Get the previous month
The day of docker run (note)
Get the number of views of Qiita
Get the attributes of an object
Get the first element of queryset
Get the number of Youtube subscribers
Python Note: Get the current month
Note: Get the first and last items of Python OrderedDict non-destructively
Get the column list & data list of CASTable
Get the minutes of the Diet via API
Get the value of the middle layer of NN
[Python] Get the character code of the file
Get the filename of a directory (glob)
[PowerShell] Get the reading of the character string
Get the list of packages for the specified user from the packages registered on PyPI
Get a datetime instance at any time of the day in Python
Get the average salary of a job with specified conditions from indeed.com
Get the contents of git diff from python
[Python] Get / edit the scale label of the figure
[Python] Get the main topics of Yahoo News
Get the caller of a function in Python
Divide the string into the specified number of characters
Get one day of the week from Zeller's joint ceremony ~ Incidentally, the perpetual calendar ~
Get Unix time of the time specified by JST regardless of the time zone of the server in Python
Find the number of days in a month
Get only the address part of NIC (eth0)
Find out the day of the week with datetime
To get the path of the currently running python.exe
Get the last element of the array by splitting the string in Python and PHP
Get the update date of the Python memo file.
Get the title of yahoo news and analyze sentiment
Get the variable name of the variable as a character string.
How to get the number of digits in Python
[Python] Get the official file path of the shortcut file (.lnk)
[Python] Get the text of the law from the e-GOV Law API
Get the sum of each of multiple columns with awk
Get the absolute path of the script you are running
[python] Get the list of classes defined in the module
Since there are many earthquakes, get the history of earthquakes
Get the return code of the Python script from bat
[C language] [Linux] Get the value of environment variable
Get to know the feelings of gradient boosting trees
Get the size (number of elements) of UnionFind in Python
Try to get the contents of Word with Golang
[Python] Get the list of ExifTags names of Pillow library
Which day of the week do you buy gold?
Set the specified column of QTableWidget to ReadOnly StyledItemDelegate
[Django 2.2] Sort and get the value of the relation destination
Get the operation status of JR West with Python
Script to get the expiration date of the SSL certificate
[Python] Get the number of views of all posted articles
Get the URL of the HTTP redirect destination in Python
The beginning of cif2cell
Get the GNOME version