I asked this question on Stack Overflow and it was closed as off-topic. I'll ask it here hoping it will do better.

This might sound silly, but bear with me. I've been working a lot with intervals and dates lately. One question that bothers me: is a day really 24 hours long? I'm interested by the answer both from a theoretical and from a practical point of view.

Let's take today for example, the day started on 13 Dec 2012 00:00:00 and according to (all) date-time implementations it will end on 14 Dec 2012 00:00:00. This is correct and the difference between the two dates is a complete 24 hours.

The problem with this is that the end date is perceived as "tomorrow". Most people thinking that a day starts on 00:00:00 and ends on 23:59:59.

So the question is: is today a closed interval at the start, and opened at the end, like [start..end), with the end being very very close to 14 Dec 2012 00:00:00 (so not really a complete 24 hours)? Or is it actually closed at both ends with a full 24 hours between them?

closed as off topic by Tom Squires, Walter, Otávio Décio, user7007, Dynamic Dec 29 '12 at 15:22

Questions on Software Engineering Stack Exchange are expected to relate to software engineering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    0-based indexing FTW! – Martijn Pieters Dec 29 '12 at 12:24
  • 3
    Don't forget leap seconds. – Martin York Dec 29 '12 at 13:48
  • 8
    What are the downvotes all about? This seems more pertinent than a lot of the other questions I see on here and right now there are two different answers with a few upvotes each so it definitely seems like a worthwhile question. – Lucifer Sam Dec 29 '12 at 13:59
  • 1
    Side note: With the half-open interval [start, end) you'd say end = first instant of the next day (in your example, 00:00:00 on the 14th) and by the definition of that kind of interval, that's the first point that's not part of the range you describe (so you don't have to worry about "the end being very very close to" that). – user7043 Dec 29 '12 at 14:18
  • 2
    @LuciferSam I didn't downvote, but one reason I could imagine is that the OP says today is 13 December. That indicates a lack of research! – Mr Lister Dec 29 '12 at 15:19

It is obviously open/closed interval. How else do you want to create continuous interval of all days and still be able to account for mili/microseconds?

And it is obviously 24 hour long. That single second between 23:59:59 and 00:00:00 still counts.

  • 6
    +1 - in addition, daylight savings will cause some days in some locales to be not 24 hours. – Telastyn Dec 29 '12 at 14:58
  • A day is actually somewhere around 23 hours, 56 minutes long. At least, that's how it is when you interpret it exactly as the time it takes for the earth to rotate around its axis. In daily use this is ofcourse simplified to 24 hours but if you ever need to calculate when the earth turns then you'll have to shave off a few minutes each "day". – Jeroen Vannevel Mar 8 '14 at 2:41
  • @JeroenVannevel: that's a sidereal day. But to us, the sun is vastly more important that the rest of the stars, so the solar day is of more interest to almost everyone. And it varies in length because the Earth's orbit is not circular. The mean solar day is very close to 24 hours. – kevin cline Mar 8 '14 at 3:14

Let's take today for example, the day started on 13 Dec 2012 00:00:00 and according to (all) date-time implementations it will end on 14 Dec 2012 00:00:00

No. By convention the day starts at 00:00:00 and end at 23:59:59 (well 23:59:59.999 if you go down to milliseconds). Time is continuous, but we have to represent it by discrete values (no matter how "accurate" those values might be) and as no one time (00:00:00, for example) can exist in more than one 24 hour period we come to an agreement as to where that boundary lies.

It is therefore 24 hours long as there are 24 * 60 * 60 seconds in this interval.

There are three occasions when this isn't true:

  1. When the clocks go forward for the start of daylight saving in which case that day is 23 hours long (one hour is lost).
  2. When the clocks go back for the end of daylight saving in which case that day is 25 hours long (one hour is repeated).
  3. When a leap second is added to a day to bring the time back into sync with the solar day in which case that day is 24 hours 0 minutes and 1 second long.

If it makes it easier think of the day starting at 00:00:01 and ending at 24:00:00. This is more obviously 24 hours.

  • 1
    What about 23:59:59.999 ?? Is it 13 or 14? Learn to closed/open intervals. – Euphoric Dec 29 '12 at 13:06
  • 2
    @Euphoric - the same argument applies. – ChrisF Dec 29 '12 at 13:59
  • 2
    @ChrisF: The day does not end at 23:59:59, that's just a limitation of our quantised time representation. 23:59:59 is a point in time, not a period of time one second long. The point of time 00:00:00 is exactly at the boundary of two adjacent days. – John Bartholomew Dec 29 '12 at 14:14
  • 1
    @JohnBartholomew - which is why I said "by convention". – ChrisF Dec 29 '12 at 14:24
  • 1
    @JohnBartholomew The code point 00:00:00 represents the full second [00:00:00, 00:00:01), when our order of magnitude is full seconds. Likewise, 23:59:59 represents the full second [23:59:59, 24:00:00). So yes; when we're dealing with units of full seconds, and that convention is used, it is completely valid to say that the day ends at 23:59:59. – Izkata Dec 29 '12 at 21:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.