Separate date and time
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
20-Sep-2017 13:49:56 (cell array) How can i separate date and time in two separate variables. 20-Sep-2017 in one variable and 13:49:56 in other variable?
0 Kommentare
Antworten (3)
Andrei Bobrov
am 24 Okt. 2017
a - your cell array
t = datetime(a);
v = datevec(t);
Var1 = datetime(v(:,1:3));
Var2 = duration(v(:,4:end));
2 Kommentare
Steph
am 11 Feb. 2019
this seperates a datetetime object into a datetime and duration object.
I couldnt merge these different datetime character vectors with a double.
Peter Perkins
am 12 Feb. 2019
With no context for this comment, it's hard to provide any help.
datetiome and duration arrays display in a human-readable format, but they are not "character vectors". You almost certainly do not want to use text to store your timestamps, datetimes and durations are a much better choice.
If by "couldn't merge", you mean "create one array that contains both timestamps and other numeric data", then use a table. If you mean, "add a datetime and a numeric value", you can do that, and it will be equivalent to adding in units of days, but I would recommend against it. Use datetimes and durations, and save yourself the headache of needing to rembering what units your numbers happen to be in.
Don't mix datetime/duration with datenum/datestr. In fact, unless you have a good reason, or a version of MATLAB prior to R2014b, don't use datenum/datestr at all.
KL
am 24 Okt. 2017
if you have everything in datetime format inside the cell array, use this,
dt = [C{:}'];
datesonly = [dt.Day dt.Month dt.Year]
timesOnly = [dt.Hour dt.Minute dt.Second]
0 Kommentare
Peter Perkins
am 16 Nov. 2017
>> dt = datetime
dt =
datetime
15-Nov-2017 23:54:20
>> t = timeofday(dt)
t =
duration
23:54:20
>> d = dt - t
d =
datetime
15-Nov-2017 00:00:00
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time 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!