We've two fields from and to (of type datetime), in which the user can keep begin some time and the finish duration of a business travel, e.g.:

From: 2010-04-14 09:00
To: 2010-04-16 16:30

So, the amount of the trip is a couple of days and 7.5 hrs.

Frequently, the precise occasions aren't known ahead of time, therefore the user makes its way into the dates with no time:

From: 2010-04-14
To: 2010-04-16

Internally, this really is saved as 2010-04-14 00:00 and 2010-04-16 00:00, since that is what most contemporary class libraries (e.g. .internet) and databases (e.g. SQL Server) do whenever you store a "date only" inside a datetime structure. Usually, this will make sense.

However, when entering 2010-04-16 because the to date, the consumer clearly did not mean 2010-04-16 00:00. Rather, the consumer meant 2010-04-16 24:00, i.e., calculating the amount of the trip should output 3 days, not 2 days.

I'm able to think about a couple of (pretty much ugly) workarounds with this problem (add "23:59" within the UI layer from the to area when the user didn't enter a period component give a special "dates are daysInch Boolean area store "2010-04-17 00:00" within the DB but display "2010-04-16 24:00" towards the user when the time component is "00:00" ...), all getting pros and cons. Since I Have think that this can be a not unheard of problem, I'm wondering:

It is possible to "standard" best-practice method of fixing it?

If there is not, perhaps you have experienced an identical requirement, how have you solve it and what were the professionalsOrnegatives of this solution?

There is not a miracle method of doing this that considerably enhances on storing 23:59 (or whatever degree of precision you want) within the 'to' area.

This kind of requirement appears in insurance plan administration systems used within U.S. areas. Frequently, beginning and expiry dates need to be recorded using the time, and expiry dates are recorded as xxxx-xx-xx 23:59. Sadly, there is no miracle formula with this, apart from defaulting time component onto: fields to 23:59.

The easiest way IMO is by using a platform or class library which does have the idea of "to start dating ?Inch outside of "a time and dateInch and also the many versions on the party's theme. (Remember the chance that between "from" and "to" there might be a daylight saving transition :)

In Java I'd suggest using Joda Time insInternet my Noda Time project will hopefully be the greatest solution when it is ready.

So within this situation you absolutely have to know whether to start dating ? was joined or night time - they are essentially different. Quite that which you do when they enter "from" like a date and "to" like a date/time, I am unsure... most likely still use "oncoming of day" for that "from" and also the with time for that "to"... but it is a little dodgy.

Essentially though, gradually alter store all the details you are aware of only the data you realize - so without having separate types, storing another "case to start dating ?Inch area appears reasonable. It's ugly, but that is since the platform is not assisting you around it will.