MATLAB: Rearranging dates to make them suitable for datetime format

filtering dates

Hi,
I have a cell array with many dates that were imported from an excel file.
Each cell array entry has differnt inputs ie 08/21/2020 (Aug), 05/26/2018 (May), 04/03/2016, 02/06/2005 (QQ).
I just neee the dates and then import them as datetime format. How can I cut the brackets out so that I can import the file into a datetime format. Remember that some of the dates above dont have brackets.
Thanks

Best Answer

>> C = {'08/21/2020 (Aug)';'05/26/2018 (May)';'04/03/2016';'02/06/2005 (QQ)'};
>> D = datetime(regexp(C,'^.{10}','match','once'),'InputFormat','MM/dd/yyyy')
D =
21-Aug-2020
26-May-2018
03-Apr-2016
06-Feb-2005