Number to datetime from textdata

1 view (last 30 days)
Mikkel Ibsen
Mikkel Ibsen on 15 Mar 2018
Edited: dpb on 15 Mar 2018
Hi
I have this data that comes in a text document like this:
"%20180313123648396"
"%20180313123656586"
"%20180313123657351"
"%20180313123658552"
"%20180313123659316"
I need a way for matlab to read the numbers and then make it into a datetime.
So they would come out like:
13-03-2018 12:36:48
13-03-2018 12:36:57
13-03-2018 12:36:57
13-03-2018 12:36:59
13-03-2018 12:36:59
How do I do that? I know how to remove the % sign, but i cant make a number into a datetime, I've tried to sat the InputFormat to: yyyyMMDDHHMMSS but it cannot read it.
Please help
  1 Comment
Greg
Greg on 15 Mar 2018
Edited: Greg on 15 Mar 2018
Help us first - what have you tried? Post the relevant code.

Sign in to comment.

Accepted Answer

dpb
dpb on 15 Mar 2018
Edited: dpb on 15 Mar 2018
If I put your exact text in a file then
>> fmt='%{%yyyyMMddHHmmssSSS}D'
fmt =
%{%yyyyMMddHHmmssSSS}D
>> fid=fopen('mikkel.dat');
>> d=textscan(fid,fmt,'collectoutput',1)
d =
cell
[5×1 datetime]
>> fid=fclose(fid);
>> d=d{:}
d =
5×1 datetime array
%20180313123648396
%20180313123656586
%20180313123657351
%20180313123658552
%20180313123659316
>> d.Format='default'
d =
5×1 datetime array
13-Mar-2018 12:36:48
13-Mar-2018 12:36:56
13-Mar-2018 12:36:57
13-Mar-2018 12:36:58
13-Mar-2018 12:36:59
>>

More Answers (0)

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!