def check_datetime(method, dictionary, fields, label=None):
    """Checks if the specified fields are formatted correctly if they have a value.
    Throws an exception on incorrectly formatted fields.

    :param dict dictionary: Dictionary to check.
    :param typle fields: Fields to check.
    :param string label: Dictionary name.
    """
    improperly_formatted = []
    values = []
    for field in fields:
        if field in dictionary and dictionary[field] is not None:
            if type(dictionary[field]) not in (datetime.datetime, datetime.date) and not ISO_8601_REGEX.match(dictionary[field]):
                improperly_formatted.append(field)
                values.append(dictionary[field])
    if improperly_formatted:
        error_label = ' for "%s"' % label if label else ''
        raise PyCronofyValidationError(
            'Method: %s. Improperly formatted datetime/date field(s)%s: %s\n%s' % (
                method, error_label, improperly_formatted, values),
            method,
            improperly_formatted,
            values
        )
Checks if the specified fields are formatted correctly if they have a value.
    Throws an exception on incorrectly formatted fields.

    :param dict dictionary: Dictionary to check.
    :param typle fields: Fields to check.
    :param string label: Dictionary name.