function [BOGcast_closest_time, BOGtime, spraytime] = findClosestTimeBOGcast(s, B, prof)
    % Extract spraytime from s using the profile index
    spraytime = s.sdn(prof);

    % Convert B.DATE_TIME to serial date numbers
    bogtime = datenum(B.DATE_TIME);

    % Calculate the absolute differences between spraytime and bogtime
    timediffs = abs(spraytime - bogtime);

    % Find the minimum difference and its index
    [~, midx] = min(timediffs);

    % Get the cruise and siteID corresponding to the minimum time difference
    cruise = B.CRUISE{midx};
    siteID = B.SITE_ID{midx};

    % Find all entries in B that match the cruise and siteID
    idx = contains(B.CRUISE, cruise) & contains(B.SITE_ID, siteID);

    % Return the subset of B that matches the criteria
    BOGcast_closest_time = B(idx, :);

    BOGtime = table2array(BOGcast_closest_time(1,"DATE_TIME"));
    spraytime = datetime(datevec(s.sdn(prof)));

    % maybe add a section for if it is nans
end
