How to convert time column to from HH:MM:SS to minutes and seconds?

45 views (last 30 days)
I have a doubt , I want to convert Time column ( HH:MM:SS) to min, there is a direct command time2num but it requires toolbox and it's paid.So without using time2num how can I convert into minutes. I tried with datetime also but I got error.
table=readtable('sample.csv'):
times = datetime(table.Time,'InputFormat','HH:mm:ss:SSS');
times = hour(times).*60 + minute(times) + second(times)./60;

Accepted Answer

Chunru
Chunru on 1 Sep 2021
% table=readtable('sample.csv'):
A=readtable('sample.csv') % table is a function name in matlab
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
A = 621×4 table
StoreNo_ Date Time Millisecond ________ ______________ ________ ___________ 2 {'2020/09/16'} 09:19:04 87 3 {'2020/09/16'} 09:19:06 88 4 {'2020/09/16'} 09:19:08 88 5 {'2020/09/16'} 09:19:10 88 6 {'2020/09/16'} 09:19:12 86 7 {'2020/09/16'} 09:19:14 91 8 {'2020/09/16'} 09:19:16 91 9 {'2020/09/16'} 09:19:18 92 10 {'2020/09/16'} 09:19:20 92 11 {'2020/09/16'} 09:19:22 96 12 {'2020/09/16'} 09:19:24 96 13 {'2020/09/16'} 09:19:26 97 14 {'2020/09/16'} 09:19:28 89 15 {'2020/09/16'} 09:19:30 89 16 {'2020/09/16'} 09:19:32 90 17 {'2020/09/16'} 09:19:34 90
class(A.Time) % A.Time is duration and it is not the time
ans = 'duration'
%times = datetime(A.Time,'InputFormat','HH:mm:ss:SSS')
% times = hour(times).*60 + minute(times) + second(times)./60;
% you are finding minutes from A.Time
t_minutes = minutes(A.Time)
t_minutes = 621×1
559.0667 559.1000 559.1333 559.1667 559.2000 559.2333 559.2667 559.3000 559.3333 559.3667

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!