Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the diffrence beetween Days and TotalDays? [closed]

Tags:

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.

like image 588
Ash Smith Avatar asked Aug 08 '14 21:08

Ash Smith


People also ask

Why is TotalDays a double?

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.

What is TotalDays C#?

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.


1 Answers

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]

like image 109
Tim Schmelter Avatar answered Oct 02 '22 18:10

Tim Schmelter