How to merge datetime and duration in two different columns?

3 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Steven Lord
Steven Lord am 15 Mär. 2020
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'

Weitere Antworten (0)

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!

Translated by