How to separate date and time into two columns

I have a datetime column with 3000+ inputs. The data is in the form of '27-Feb-2020 15:15:11' etc. I want to separate the date (27-Feb-2020) from the time. Ideally they would be in two columns instead of 1.

Answers (1)

Try something like this
a = datetime('27-Feb-2020 15:15:11');
b = datetime('29-Feb-2020 15:15:11');
M = (a:b)'; % sample datetime vector
[y,m,d] = ymd(M);
[h,M,s] = hms(M);
t = table(datetime(y,m,d), duration(h,m,s), 'VariableNames', {'date', 'time'});

Categories

Tags

Asked:

on 22 Mar 2020

Answered:

on 22 Mar 2020

Community Treasure Hunt

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

Start Hunting!