MATLAB Answers

extracting datetime from csv file

9 views (last 30 days)
Rose on 30 Dec 2019
Commented: Star Strider on 30 Dec 2019
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
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!


Sign in to comment.

Accepted Answer

Star Strider
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')
t =
10-Aug-2016 00:39:47


Rose on 30 Dec 2019
Thank you! That works perfectly!
Star Strider
Star Strider on 30 Dec 2019
As always, my pleasure!

Sign in to comment.

More Answers (0)

Sign in to answer this question.