How to merge datetime and duration in two different columns?
12 次查看(过去 30 天)
显示 更早的评论
I have two columns with dates in first column and duration in second column. It is 999x4 timetable. Also the date is in format '13/02/0020' and not in '13/02/2020'. I have used following code to convert the original date in form of '13.02.2020'(cell array) to date time object
d=NewP{:,'Date'}
d1=datetime(d,"Locale","de_DE");
d1.Format='dd/MM/yyyy'
NewP.Date=d1
I want to plot a line graph between meltcushion and time for two different dates i.e 13/02 and 28/02, the graph is coming in the following form.
The data was taken at two different dates and both were taken from '9.30 am to 2.30 pm'.
My aim is to plot the graph at two different dates together. My desired output for column as following example
dt=datetime('today')
dnt=dt+NewP{1,"Time"}
dnt =
15-Mar-2020 09:32:57
But when I use the above example to merge the both columns
0 个评论
采纳的回答
Steven Lord
2020-3-15
You told MATLAB you wanted to use the format 'dd/MM/yyyy' to display d1. Adding a duration to a datetime doesn't change the Format. But just because the duration data isn't displayed doesn't mean it was discarded.
% Make a datetime
dt = datetime('today', 'Format', 'dd/MM/yyyy')
% Add time data without affecting the Format
dt = dt + hours(0:23).'
% Show that there is actually a difference between elements in dt
% even though that difference is not visible due to the Format
dt(17)-dt(1)
% Change the Format to show the time data
dt.Format = 'dd/MM/yyyy HH:mm'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!