How to make a table with date times and durations?
13 views (last 30 days)
Show older comments
Hi, I have a set of datetimes and durations, and I want to merge them and display them in a table. I just can't figure out how to set the timezones, keep on getting errors. Any help is appreciated, I attached the files for extra clarity.
Thanks!
0 Comments
Accepted Answer
dpb
on 19 Jul 2021
>> t=table(rampD_start,rampD_end,'VariableNames',{'Start','End'});
>> head(t)
ans =
8×2 table
Start End
____________ ____________
May-03 11:37 May-03 11:55
May-05 11:00 May-05 11:07
May-21 12:00 May-21 12:24
May-25 17:23 May-25 17:43
May-26 11:37 May-26 12:00
May-28 11:39 May-28 12:01
May-31 12:18 May-31 12:41
Jun-02 10:20 Jun-02 10:42
>> t.Span=t.End-t.Start;
Cannot combine or compare a datetime array with a time zone with one without a time zone.
>> t.Start.TimeZone
ans =
0×0 empty char array
>> t.End.TimeZone
ans =
'Europe/Amsterdam'
>> t.Start.TimeZone=t.End.TimeZone;
>> t.Span=t.End-t.Start;
>> head(t)
ans =
8×3 table
Start End Span
____________ ____________ ________
May-03 11:37 May-03 11:55 00:18:00
May-05 11:00 May-05 11:07 00:07:00
May-21 12:00 May-21 12:24 00:24:00
May-25 17:23 May-25 17:43 00:20:00
May-26 11:37 May-26 12:00 00:23:00
May-28 11:39 May-28 12:01 00:22:00
May-31 12:18 May-31 12:41 00:23:00
Jun-02 10:20 Jun-02 10:42 00:22:00
>>
Or, of course, you can remove the TimeZone from both if don't want to keep it.
Alternatively, go back to the creation of the data from which the two datetime arrays came and ensure they're imported the same way to avoid the mismatch in the beginning.
0 Comments
More Answers (1)
Sameer Pujari
on 19 Jul 2021
Table can be found simply using this
T=table(rampD_start,rampD_end,rampD_dur)
0 Comments
See Also
Categories
Find more on Tables 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!