TimeSpan.TotalDays Property

Definition

Gets the value of the current TimeSpan structure expressed in whole and fractional days.

C#
public double TotalDays { get; }

Property Value

The total number of days represented by this instance.

Examples

The following example instantiates a TimeSpan object and displays the value of its TotalDays property. It also displays the value of each component (hours, minutes, seconds, milliseconds) that forms the fractional part of the value of its TotalDays property.

C#
// Define an interval of 3 days, 16+ hours.
TimeSpan interval = new TimeSpan(3, 16, 42, 45, 750); 
Console.WriteLine("Value of TimeSpan: {0}", interval);

Console.WriteLine("{0:N5} days, as follows:", interval.TotalDays);
Console.WriteLine("   Days:         {0,3}", interval.Days);
Console.WriteLine("   Hours:        {0,3}", interval.Hours);
Console.WriteLine("   Minutes:      {0,3}", interval.Minutes);
Console.WriteLine("   Seconds:      {0,3}", interval.Seconds);
Console.WriteLine("   Milliseconds: {0,3}", interval.Milliseconds);

// The example displays the following output:
//       Value of TimeSpan: 3.16:42:45.7500000
//       3.69636 days, as follows:
//          Days:           3
//          Hours:         16
//          Minutes:       42
//          Seconds:       45
//          Milliseconds: 750

Remarks

This property converts the value of this instance from ticks to days. This number might include whole and fractional days.

The TotalDays property represents whole and fractional days, whereas the Days property represents whole days.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

See also