Convert hour, minute, and day to fraction of a day

Was doing something a few weeks ago in which we had to convert the date to a fraction of a day (hour and minutes) but this time we have to do hour, minute, and seconds. Assuming the process would be similar but having difficulties with the seconds aspect.
This is the code:
fracday = (1/24){floor (HHMM * 0.01) + [(HHMM * 0.01 - Floor (HHMM * 0.01)) / 0.6]

 Accepted Answer

The easiest is to use the days function with a duration object:
>> days(duration(5,3,10)) %fraction of a day for 5 hours, 3 minutes, 10 seconds
ans =
0.210532407407407
>> days(duration(47,59,59)) %fraction of days for 47 hours, 59 minutes, 59 seconds
ans =
1.99998842592593

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!