def strftime_all_years(dt, fmt):
    """Exactly like datetime.strftime but supports year<1900."""
    assert '%%Y' not in fmt  # unlikely but just in case
    if dt.year >= 1900:
        return dt.strftime(fmt)
    else:
        return dt.replace(year=1900).strftime(fmt.replace('%Y', '%%Y')).replace('%Y', str(dt.year))