How to merge datetime and duration in two different columns?
조회 수: 2 (최근 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에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!