A compact way to extract a date from a filename and transform it into a datetime

1 view (last 30 days)
A compact way to extract a date from a filename and transform it into a datetime ?
E.g. from
'20210317.csv'
to
ans =
datetime
17-Mar-2021

Accepted Answer

Sim
Sim on 9 Aug 2022
Edited: Sim on 9 Aug 2022
found it:
s = '20210317';
datetime(s, 'InputFormat', 'yyyyMMdd')
which gives this:
ans =
datetime
17-Mar-2021

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!