Separating datetime data ('yyyy-MM-dd HHmm:ss' Into 'hh:mm:ss')

3 views (last 30 days)
Tyann Hardyn
Tyann Hardyn on 3 Dec 2021
Edited: dpb on 3 Dec 2021
Hi, Community ~
I have a simple question... I have a datetime data like this :
2017-12-31 23:34:00
2017-12-31 23:35:00
2017-12-31 23:36:00
2017-12-31 23:37:00
2017-12-31 23:38:00
2017-12-31 23:39:00
2017-12-31 23:40:00
2017-12-31 23:41:00
2017-12-31 23:42:00
2017-12-31 23:43:00
2017-12-31 23:44:00
2017-12-31 23:45:00
2017-12-31 23:46:00
2017-12-31 23:47:00
2017-12-31 23:48:00
2017-12-31 23:49:00
2017-12-31 23:50:00
I just want to know, how to convert it or extract the data to become duration only? (I want to get the duration Data only)
23:34:00
23:35:00
23:36:00
23:37:00
23:38:00
23:39:00
23:40:00
23:41:00
23:42:00
23:43:00
23:44:00
23:45:00
23:46:00
23:47:00
23:48:00
23:49:00
23:50:00
Whats the code for the extraction or conversion? Thank you so much...

Accepted Answer

dpb
dpb on 3 Dec 2021
See
doc timeofday
NB: When you have an area of functionality but don't know the function name, the "Functions" link at the top of the documentation page for any function in the area for which you do know the name will provide an annotated list of all the related functions.
In this case, if you bring up the doc for datetime, you'll have that link at the top of the page and will find timeofday listed.
I notice the description for it isn't the best; I'll try to take the time to write a suggestion for upgrading the documentation; it has the function listed in area to return numeric values which could be improved to note it returns a duration.
It took me ages to figure this out in the new documentation myself; before there was the lookfor function at the command line or help for a toolbox or area of a given set of functionalities by the area of the MATLABPATH folder; that hasn't been kept up and owing to the massive growth of functionality it isn't nearly as useful as it once was -- but the "functions" list is invaluable tool.
  2 Comments
dpb
dpb on 3 Dec 2021
It seems like it, but was introduced at the same time as the datetime and duration classes were released in R2014b so it's getting to be a fair time since...
The documentation now includes an introduction date at the end of every function for everything since R2006b. There's much to be learned by exploring the documentation in greater depth than the most cursory glance at the top.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!