Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating a whole day c#

Tags:

c#

This is to resolve a difference in opinion in the office on what a full day consists of.

to represent a whole day (to the second) I would say:

2011/03/03 00:00:00 - 2011/03/04 00:00:00 = one full day.

eg:

TimeSpan test = new DateTime(2011, 03, 04, 00, 00, 00) - new DateTime(2011, 03, 03, 00, 00, 00); 

The above code gives test a value of 1.00:00:00, therefore one full day.

Other opinion in the office:

2011/03/03 00:00:00 - 2011/03/03 23:59:59 = one full day.

If anyone can be bothered replying to this!! Which do they think is correct?

EDIT:

A few months has passed and the two people in the office with the "other opinion" are no longer employed here...

like image 814
Oliver Avatar asked Mar 03 '11 14:03

Oliver


People also ask

What is the formula for calculating CCC?

CCC Formula = DIO + DSO – DPO For which you're calculating the CCC. For instance, if you're calculating it for a quarter, you would need to use 90 days and if you are calculating it for the entire year, you would use 365 days.

How do you calculate days in inventory?

Days in inventory is calculated by dividing average inventory (in dollars) over a given time by cost of goods sold (COGS) during that period and multiplying the result by the number of days in the period (typically a quarter or a year).


2 Answers

As a side note, if you want the time interval of a specific day, be aware that not all days have 24 hours.

Some days have leap seconds, which makes them one second longer.

Daylight savings time changes make days have 23 or 25 hours (depending on the change).

like image 89
Jordão Avatar answered Sep 19 '22 01:09

Jordão


You want one day, ask for one day:

TimeSpan oneDay = TimeSpan.FromDays(1);

The interval [2011/03/03 00:00:00, 2011/03/04 00:00:00[ spans one entire day. Notice that the upper bound is open. If your granularity is no less than one second, then that interval is exactly the same as [2011/03/03 00:00:00, 2011/03/03 23:59:59] (closed upper bound). Hope this clears up both points of view.

You can also say that you are thinking in terms of instants, and your coworkers are thinking in terms of one second periods. Imagine a long fence constructed with several wooden poles and each pair of consecutive poles is connected with a string of wire of the same length. You can say that the fence goes from pole 0 to pole 10, and your coworkers can say that the fence goes from string 0 to string 9.

Depending on what you're trying to do, both views can be correct. Using one of these points of view in a situation that requires the other is a fencepost error.

like image 26
R. Martinho Fernandes Avatar answered Sep 20 '22 01:09

R. Martinho Fernandes