extracting datetime from csv file
18 views (last 30 days)
Show older comments
Hey there,
I'm trying to import a csv file with sensor data, which are measurements on set times.
The second column of the file contains the date time stamps of the sensor values, which are stored in the columns afterwards (3th, 4th, 5th column etc).
The format of the time stamps is the following: 2016-08-10 00:39:47+00:00
Now i'm facing 2 difficulties, first of all, this time stamp is not in accordance with the usual date time stamp due to the addition of +00:00, which is the same addition for every time stamp and could thus be removed (if I figure out how).
Secondly, I cant seem to get the datetime command to work for my file... I have tried the following code:
sensordata=datetime('Measurement.csv','Range', 'B2:B41') %but this does not work at all because range is not allowed
%I also tried first extracting only the second column into a cell array, and then afterwards using the datetime command, but this also resulted in the error below
January=readtable('Measurement.csv')
sensordata=January(:,2);
sensordataarray=table2array(sensordata);
time=datetime(sensordataarray,'Locale', 'en_US');
Error using datetime (line 636)
Could not recognize the format of the date/time text using the locale 'en_US'. You can specify a format using the
'InputFormat' parameter.
Any clues on how to remove the +00:00 (which i assume is part of the error as well), or how to get an array with datetime values?
Thank you!
0 Comments
Accepted Answer
Star Strider
on 30 Dec 2019
I am not certain what the ‘+00:00’ does, however eliminating it is straightforward.
Try this:
t = datetime('2016-08-10 00:39:47+00:00', 'InputFormat','yyyy-MM-dd HH:mm:ss+00:00')
producing:
t =
datetime
10-Aug-2016 00:39:47
2 Comments
More Answers (0)
See Also
Categories
Find more on Tables 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!