def format_date(value, format='%b %d, %Y', convert_tz=None):
    """
    Format an Excel date or date string, returning a formatted date.
    To return a Python :py:class:`datetime.datetime` object, pass ``None``
    as a ``format`` argument.

    >>> format_date(42419.82163)
    'Feb. 19, 2016'

    .. code-block:: html+jinja

        {{ row.date|format_date('%Y-%m-%d') }}
    """
    if isinstance(value, float) or isinstance(value, int):
        seconds = (value - 25569) * 86400.0
        parsed = datetime.datetime.utcfromtimestamp(seconds)
    else:
        parsed = dateutil.parser.parse(value)
    if convert_tz:
        local_zone = dateutil.tz.gettz(convert_tz)
        parsed = parsed.astimezone(tz=local_zone)

    if format:
        return parsed.strftime(format)
    else:
        return parsed