OCLOperators TotalHours
.TotalHours returns the whole length of a TimeSpan in hours, as a decimal number. Days are converted to hours, and the minutes, seconds and milliseconds left over become the fractional part.
Syntax
aTimeSpan.TotalHours
Returns
Double
Example
(DateTime.Parse('2026-11-23 14:30:00.250') - DateTime.Parse('2026-11-20 08:15:30')).TotalHours
Result: 78.2417361111111
The TimeSpan is 3.06:14:30.250: 3 days × 24 = 72 hours, plus 6 hours, plus 14 minutes 30.25 seconds as a fraction of an hour.
Model example
Hours since an employee record was last updated, in the context of Employee:
(DateTime.Now - self.UpdatedOn).TotalHours
Notes
- A negative TimeSpan gives a negative result.
- To get just the hours part (0–23), use Hours.
