Note that there are some explanatory texts on larger screens.

plurals
  1. POThe woes of (sometimes) storing "date only" in datetimes
    primarykey
    data
    text
    <p>We have two fields <code>from</code> and <code>to</code> (of type <code>datetime</code>), where the user can store the begin time and the end time of a business trip, e.g.:</p> <pre><code>From: 2010-04-14 09:00 To: 2010-04-16 16:30 </code></pre> <p>So, the duration of the trip is 2 days and 7.5 hours.</p> <p>Often, the exact times are not known in advance, so the user enters the dates without a time:</p> <pre><code>From: 2010-04-14 To: 2010-04-16 </code></pre> <p>Internally, this is stored as <code>2010-04-14 00:00</code> and <code>2010-04-16 00:00</code>, since that's what most modern class libraries (e.g. .net) and databases (e.g. SQL Server) do when you store a "date only" in a datetime structure. Usually, this makes perfect sense.</p> <p>However, when entering <code>2010-04-16</code> as the <code>to</code> date, the user clearly did <em>not</em> mean <code>2010-04-16 00:00</code>. Instead, the user meant <code>2010-04-16 24:00</code>, i.e., calculating the duration of the trip should output <code>3 days</code>, not <code>2 days</code>.</p> <p>I can think of a few (more or less ugly) workarounds for this problem (add "23:59" in the UI layer of the <code>to</code> field if the user did not enter a time component; add a special "dates are full days" Boolean field; store "2010-04-17 00:00" in the DB but display "2010-04-16 24:00" to the user if the time component is "00:00"; ...), all having advantages and disadvantages. Since I assume that this is a fairly common problem, I was wondering:</p> <ul> <li>Is there a "standard" best-practice way of solving it?</li> <li>If there isn't, have you experienced a similar requirement, how did you solve it and what were the pros/cons of that solution?</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload