Writing data type calendarDuration to Excel?
3 views (last 30 days)
Show older comments
I'm writing Matlab dates and times to Excel. I see that the function "exceltime" converts datetime data so that they can be written to Excel, but that function doesn't work on calendarDuration types. (calendarDuration is the result of applying caldiff). I realize I can use Excel to determine elapsed time, but I prefer to calculate it in Matlab and write it out to Excel. How do I convert calendarDuration types so they can be written to Excel?
Thanks, Aram
0 Comments
Answers (1)
Peter Perkins
on 20 Nov 2017
Aram, Excel's notion of time is more or less equivalent to a datenum in MATLAB (with a different offset). In other words, a count of days + fractional days, either from an implied offset of "0"-Jan-1900 (if you are talking about an absolute time), or just the raw count (if you are talking about elapsed time). I don't know all the details of Excel's internals, but my impression is that to distinguish absolute from elapsed time, you change the display format.
A calendarDuration is a much subtler thing, in effect a 3-tuple comprising a count of months, days, and seconds, and in general it's not possible to turn that into a single number (how many days in a month? it depends. How many seconds in a day? it depends). In that sense, a calendarDuration is more like a datevec, not a datenum. It may be that you've called caldiff to get just the number of days, and for special cases like that you can certainly write out something (probably you'd convert to numeric using the days function).
I think you'll need to say more.
3 Comments
Peter Perkins
on 29 Nov 2017
seconds(diff(t)), or minutes, or whatever, creates a numeric "single-unit" value that you can write to a spreadsheet. days would create a value that Excel would sort of be able to recognize as it's own time representation - I think you could set Excel's display format as something like hh:mm:ss for cells into which you've written.
See Also
Categories
Find more on Calendar 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!