import re


def _prepare_date(from_date):
    """
    Private function to prepare from_date by converting
    it to YYYY-MM-DD format.
    """
    # check if from_date was provided and if it was provided in the right
    # format
    from_date_str = None
    if from_date is not None:
        if not isinstance(from_date, str):
            try:
                from_date_str = from_date.strftime('%Y-%m-%d')
            except AttributeError:
                raise ValueError(
                    f"""from_date must be a string in the format YYYY-MM-DD
                        or datetime. String provided: {from_date}"
                    """
                )
        else:
            # regex template for YYYY-MM-DD
            pattern = re.compile("\\d{4}-\\d{2}-\\d{2}")
            match = pattern.match(from_date)
            if match is None:
                raise ValueError(
                    f"""from_date must be a string in the format YYYY-MM-DD \
or datetime. String provided: {from_date}"
                    """
                )
            from_date_str = from_date[0:10]
    return from_date_str