Convert text file to Excel file with dates in the correct format?

1 view (last 30 days)
I'm trying to get my code (below) to convert FDATA.TXT (attached) to an Excel File (attached). Once in Excel, the dates all have "0:00" after them, and I want to get rid of these 0:00 times and just have the dates shown in Excel.
The text file is generated from a SD card Arduino coded in C++ (I think?). Thanks so much!
close all
clc
T = readtable('FDATA.TXT'); % read text file
T.Var3.Format = 'MM/dd/yyyy'; % I tried adjusting the date format
writetable(T,'Initial Table Data.xlsx') % convert to Excel file
  3 Comments
Walter Roberson
Walter Roberson on 14 Aug 2021
Is it mandatory that the Excel output have 3 columns? It would make more sense to treat the second input column as a duration to be added to the third input column as a datetime, giving you a result that is a unified datatime entry that has date and time together as a single column.

Sign in to comment.

Accepted Answer

Simon Chan
Simon Chan on 14 Aug 2021
You may change it to a string format and write to an excel file.
clear; clc;
T=readtable('FDATA.TXT');
T.Var3=datestr(T.Var3,'mm/dd/yyyy');
writetable(T,'Initial Table Data.xlsx');
  3 Comments
Natalie Schmidt
Natalie Schmidt on 25 Aug 2021
Thank you so much! While it worked for lines 1-95 in Excel, starting in line 96, the dates say "######" in Excel. (This is because the dates start repeating again in line 96 (starting again w/ 7/1/21- I don't know why). How can I fix that?

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!