Clear Filters
Clear Filters

convert excel time to time in a matlab

20 views (last 30 days)
In excel file (.csv) column A is in format of (12:37:48.123 AM) and I want to have it in MatLab as 12:37:48.123
I tried using the following code:
UTCtime = datetime(dat(8:lastindex), 'Format', 'hh:mm:ss:SSS a')
But got this error:
Error using datetime (line 597)
Numeric input data must be a matrix with three or six columns, or else three, six, or seven separate numeric arrays. You can also create datetimes
from a single numeric array using the 'ConvertFrom' parameter.
Error in Event_129_BATS02 (line 91)
UTCtime = datetime(dat(8:lastindex), 'Format', 'hh:mm:ss:SSS a')
Please help.

Accepted Answer

Campion Loong
Campion Loong on 18 Nov 2022
Simply use 'InputFormat' to parse the excel timestamp, and 'Format' to display it in your format of choice
% Made up data - you can parse an array in one call
excel_timestamp = ["12:37:48.123 AM"; "1:34:42.153 AM"; "3:25:31.635 AM"];
% Use the "InputFormat" & "Format" Name/Value pairs right at construction
datetime(excel_timestamp,"InputFormat","hh:mm:ss.SSS a", "Format", "hh:mm:ss.SSS")
ans = 3×1 datetime array
12:37:48.123 01:34:42.153 03:25:31.635

More Answers (0)

Community Treasure Hunt

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

Start Hunting!