How to merge datetime and duration in two different columns?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Anshul Choubey
il 15 Mar 2020
Commentato: Anshul Choubey
il 15 Mar 2020
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277262/image.png)
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'.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277263/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277264/image.png)
0 Commenti
Risposta accettata
Steven Lord
il 15 Mar 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'
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calendar in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!