Separating a timestamp into individual components

2 Ansichten (letzte 30 Tage)
Kiran Reddy
Kiran Reddy am 27 Sep. 2022
Bearbeitet: Chunru am 27 Sep. 2022
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.

Antworten (1)

Chunru
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]
ans = 4×3
20 8 2009 21 8 2009 22 8 2009 23 8 2009
% alternatively use datetime
dt = datetime(string(times), "InputFormat", "ddMMyyyy");
dt
dt = 4×1 datetime array
20-Aug-2009 21-Aug-2009 22-Aug-2009 23-Aug-2009
[day(dt), month(dt), year(dt)]
ans = 4×3
20 8 2009 21 8 2009 22 8 2009 23 8 2009

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by