from datetime import datetime


def formatted_mrec_value_str(value: str, datetimefmt: str) -> str:
    """Returns the formatted value of a metadatum record. That is, in case the
    corresponding metadatum has a datetimefmt set, it will apply the format to
    the value of the metadatum and return the result, otherwise the value of
    the metadatum is returned unchanged.

    Arguments:
        value         : The metadatum record value
        datetimefmt   : The metadatum record datetimefmt
    """
    if datetimefmt is not None:
        try:
            return datetime.fromisoformat(value).strftime(datetimefmt)
        except ValueError:
            pass
    return value