Can anybody tell me what is the difference between these two functions in C#? TotalDays and Days because I'm not sure which once I should use in my code? Sorry for the low information on this text, but there is not much I can talk about.
TotalDays is a double because it represents whole and fractional days whereas Days is an int which represents only whole days. That is even mentioned explicitly in the remarks sections of TimeSpan.
TotalDays returns a double representing whole and fractional days (positive or negative). The key is that each component of a TimeSpan with negative value is itself a negative value or 0, and vice versa. This relationship applies to TotalHours/Hours, TotalMinutes/Minutes, etc. as well.
Since i haven't found a duplicate i post my comment here:
Always read the documentation first. TotalDays
is a double
because it represents whole and fractional days whereas Days
is an int
which represents only whole days.
That is even mentioned explicitly in the remarks sections of TimeSpan.Days
/TotalDays
:
The Days property represents whole days, whereas the TotalDays property represents whole and fractional days.
One thing to note, as opposed to the other properties in TimeSpan
like Hours
/TotalHours
there is no limit on Days
. So it doesn't end with 30 or 365(like Hour
which ranges from -23 through 23) since there is no larger unit than year. So Days
will always be the same number as (int) ts.TotalDays
.
A
TimeSpan
doesn't have a sensible concept of "years" because it depends on the start and end point. (Months is similar - how many months are there in 29 days? Well, it depends...) [J. Skeet]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With