def last_day_of_month_by_date(date):
"""Returns the last day of the month given in date.
It returns date with the same properties as the original
one, except that the result will be on the last date in
the month of the original argument.
"""
_, last_day = calendar.monthrange(date.year, date.month)
return date.replace(day=last_day)