def find_nearest_date(items, pivot):
    """This function will return the datetime in items which is the closest to the date pivot.
    See https://stackoverflow.com/questions/32237862/find-the-closest-date-to-a-given-date

    Parameters
    ----------
    items : list
        List containing datetimes
    pivot : datetime.datime
        Datetime to be found

    Returns
    -------
    datetime.datetime

    """
    return min(items, key=lambda x: abs(x - pivot))