how to convert time in its standard form to seconds?

Hi Team,
I have time in its standard format Hh:mm.ss loaded from excel sheet. how can i convert it into complete seconds which helps me in further calculation.

 Accepted Answer

Use datenum.
t1 = '12:45:07';
t2 = '13:45:07';
dt_sec = round((datenum(t2,'HH:MM:SS') - datenum(t1,'HH:MM:SS'))*(24*3600))
dt_sec =
3600

4 Comments

Hi Kim,
t1 = '12:45:07';
t2 = '13:35:07';
dt_sec = round((datenum(t2,'hh:mm:ss') - datenum(t1,'hh:mm:ss'))*(24*3600))
dt_sec =
-26262000
Output is wrong
Radhika, was too quick with the pasting. It should, of course, be upper-case letters: 'HH:MM:SS'. See code above.
Hi Kim,
Can i consider millisecond in above format??

Sign in to comment.

More Answers (0)

Tags

Asked:

on 10 Mar 2014

Commented:

on 18 Mar 2014

Community Treasure Hunt

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

Start Hunting!