Separating a timestamp into individual components
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have time stamps in a vector with the form DDMMYYYY. Is there any way to seperate all of the elements so I can have a date column DD, a month column MM and a year column YYYY for each individual row.
The first few lines of the vector are below:
times =
20082009
21082009
22082009
23082009
And I am trying to get it in the form below so each component of the time stamp and its corresponding data are set out in different columns.
20 08 2009
21 08 2009
22 08 2009
23 08 2009
I have tried some of the methods listed in similar threads but they didn't seem to work for this format. The times vector only includes a column of these timestamps with the corresponding data and the table headings removed.
0 Kommentare
Antworten (1)
Chunru
am 27 Sep. 2022
Bearbeitet: Chunru
am 27 Sep. 2022
times = [
20082009
21082009
22082009
23082009];
d = floor(times/1e6);
m = mod(floor(times/1e4), 100);
y = mod(times, 10000);
[d m y]
% alternatively use datetime
dt = datetime(string(times), "InputFormat", "ddMMyyyy");
dt
[day(dt), month(dt), year(dt)]
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!