MATLAB Answers

How do I read a text file and convert the dates and time?

19 views (last 30 days)
Sonima on 25 Jul 2018
Edited: Sonima on 15 Aug 2019
Hi! I have a text file that includes the following:
2015-06-18 12:00

Accepted Answer

jonas on 25 Jul 2018
Edited: jonas on 25 Jul 2018
Your format string is wrong, try
datenum(tt,'yyyy-mm-dd HH:MM');
better yet, use datetime

More Answers (1)

Peter Perkins
Peter Perkins on 3 Aug 2018
It's likely that you want to read the file using readtable, and if you are using a recent version of MATLAB, you will get datetimes automatically. If not, you can convert to datetime after importing.
You are better off using datetime than datenum.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!