def date_to_str(dt, with_timezone=False):
    """
    Convert datetime to str

    Parameters
    ----------
    dt : datetime
        datetime to convert
    with_timezone : bool, default False
        Include timezone or not

    Returns
    -------
    datetime_str : str
        Datetime string
    """
    if with_timezone and dt.tzinfo:
        dtstr = dt.strftime("%Y-%m-%dT%H:%M:%S.%f%z")
        return dtstr[:-2] + ":" + dtstr[-2:]
    else:
        return dt.strftime("%Y-%m-%dT%H:%M:%S.%f")