# 月末(EOM, EndOfMonth)

# 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
}
get_eom 20150509

# Excel

=EOMONTH(TODAY(), 0)

# PHP

$d->format('Y-m-t');

# Python

def get_eom(d):
  return datetime.date(d.year, d.month, calendar.monthrange(d.year, d.month)[1])
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

# Ruby

def get_eom(d)
  ((d - d.day + 1) >> 1) - 1  # 月初の1か月後の1日前
end

Rails の場合、

Date.today.end_of_month

[ 📩 ご意見 ]