How to separate date and time into two columns
Show older comments
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)
Ameer Hamza
on 22 Mar 2020
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
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!