Is it possible to convert a duration array to something else like a number or string?

249 views (last 30 days)
When finding the difference between two datetime scalars the result is a duration array. And i need it to be a double or a string.

Accepted Answer

Steven Lord
Steven Lord on 19 Dec 2016
Edited: Steven Lord on 13 Jan 2019
If you convert the duration to a double, what should it represent? The number of years, days, hours, minutes, seconds, or milliseconds that duration represents? See the functions that have those names on the documentation page to which I linked.
[Edited to update broken link.]
Steven Lord
Steven Lord on 13 Jan 2019
The link broke. I updated it to point to the page listing the functions you can use to create or manipulate a datetime or duration array. See the links to the years, days, hours, minutes, seconds, and milliseconds documentation pages on that page.

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 19 Dec 2016
You can apply char() to a duration object. You can set the Format property of the duration object before using char()

Mohammad Kifayath Chowdhury
This could be useful,
Tx=hours(Tx); This will give the hours value as double.


Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!