MATLAB: Add time to datetime format datetime format without time Hi, I have a datetime format in the following format (MM-dd-yyyy), but it does not have time. How can I add time to it for instance 00:00 (midnight) so I get the format MM-dd-yyyy HH:mm:ss. Best Answer Try this: de = ['08/21/2020 (Aug)'; '09/21/2020 (Sep)']DT = datenum(de, 'mm/dd/yyyy')DS = datestr([DT + zeros(size(DT,1),1)], 'mm/dd/yyyy HH:MM:SS')producing: DS = 2×19 char array '08/21/2020 00:00:00' '09/21/2020 00:00:00'or alternatively just. DS = datestr(DT, 'mm/dd/yyyy HH:MM:SS')producing the same result. . Related SolutionsMATLAB: Change imported date into datetime format Try this: de = '08/21/2020 (Aug)';DT = datetime(de, 'InputFormat','MM/dd/yyyy (MMM)')producing (using the default Format): DT = datetime 21-Aug-2020. MATLAB: Convert date to datetime t = datetime(DateStrings,'InputFormat','dd/MM/yyyy'); Related QuestionFrustrating datetime and datestrDatetime problem of converting stringRemoving time from datetimeDatestr not working properlyHow can i transfor these numbers into dates (dd / mm/ yyyy) in Matlab? 19300501 19300502 19300503 19300505
Best Answer