import datetime
import pathlib


def get_datetime_from_filename(filestring:str):
    """Takes a filename or filepath string and returns a datetime object representing the iso date in the filename
    """

    stem = pathlib.Path(filestring).stem
    isodate = stem.split('_')[-1]
    dt = datetime.datetime.strptime(isodate, '%Y%m%d')

    return dt