import calendar


def validate_days(year, month, day):
    """validate no of days in given month and year

    >>> validate_days(2012, 8, 31)
    31
    >>> validate_days(2012, 8, 32)
    31
    """
    total_days = calendar.monthrange(year, month)
    return (total_days[1] if (day > total_days[1]) else day)