月末
Python
py
def get_eom(d):
return datetime.date(d.year, d.month, calendar.monthrange(d.year, d.month)[1])
py
def get_eom(d):
tmp = d - datetime.timedelta(d.day - 1) # bom
tmp += datetime.timedelta(31) # next month
eom = tmp - datetime.timedelta(tmp.day) # this month's eom
return eom
PHP
php
$d->format('Y-m-t');
Bash
bash
function get_eom
{
CURR_BOM=`gdate +%Y%m01 -d $1`
NEXT_BOM=`gdate +%Y%m01 -d "$BOM 31 days"`
CURR_EOM=`gdate +%Y%m%d -d "$NEXT_BOM - 1 days"`
echo $CURR_EOM
}
bash
get_eom 20150509
Ruby
rb
def get_eom(d)
((d - d.day + 1) >> 1) - 1 # 月初の1か月後の1日前
end
Rails の場合、
rb
Date.today.end_of_month
Excel
xlsx
=EOMONTH(TODAY(), 0)