Convert datetime to default format
Show older comments
My input date time is 16:30:00 13-05-21. It's in HH:MM:SS dd-mm-yy format. I need to convert it into default format like this (13-May-2021 16:30:00).
I tried this but, the output comes out as NaT .
inp_time='16:30:00 13-05-21';
>> dtime=datetime(inp_time,'InputFormat','HH:MM:SS dd-mm-yy')
dtime= NaT
Can you help me here?
Answers (2)
SALAH ALRABEEI
on 7 Jun 2021
% Use 'dd-MMM-uuuu HH:mm:ss'
inp_time='16:30:00 13-05-21';
dtime=datetime(inp_time,'InputFormat','HH:MM:SS dd-mm-yy')
Have you tried swapping the M and m parts of the InputFormat as suggested by the warning messages?
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!