This is always a puzzle to me- and I realise that it is not strictly an issue in programming or software development, but it seems to be a reasonable common one in our field.

For example, if I were to set an expiry datetime as 2011-04-08 00:00:00 - and given my current local time is 10:45 on the 8th already - have I already expired? Or do I still have half a day or so left?

Is there are universal standard for which end of the day midnight 'belongs' to?

Or should I take a leaf from the British military, and say that the day ends at 23:59:59 and starts at 00:00:01 and that there is no midnight?

  • wait wait, where is your location? what date is it now? 08 or 07?
    – Sufendy
    Commented Apr 8, 2011 at 1:30
  • sry - made it clearer that I'm already on the 8th (I'm in Adelaide, SA)
    – HorusKol
    Commented Apr 8, 2011 at 2:37
  • 1
    So you are basically asking is 00:00:00 smaller or larger than 10:45:00? Commented May 11, 2011 at 12:11
  • I'd take the leaf. Many organizations that deal with schedules avoid 00:00:00 (and 12:00:00). There is also some confusion about AM / PM designators for those countries that do not use 24 hour clocks.
    – dbasnett
    Commented May 11, 2011 at 13:12
  • In some contexts 24:00:00 is used to describe midnight at the end of the day. Commented Feb 23, 2013 at 15:41

3 Answers 3


I think in programming (oracle and php, not sure 'bout other languages), midnight is the beginning of a day. For example if you trunc(sysdate) you will get 2011-04-08 00:00:00 which is our past.

so, when the clock changed from 23:59:59 to 00:00:00, the date actually changed from 2011-04-08 to 2011-04-09

  • 2
    Yes, the day rolls over at midnight, which is 00:00:00. Commented Apr 8, 2011 at 1:32
  • This is correct AFAIK. One confusion may be that in casual speech, "midnight today" probably means midnight at the end of today, because that's more likely to be before people go to bed, than after they wake up.
    – Jack V.
    Commented May 11, 2011 at 13:42

An addendum to @Phelios' answer, if you have a time like 00:00:00, this is not necessarily exactly midnight. Rather, it is an infinitely large set of points in time, that all have a maximum distance of <1 second to each other. For example, all of 00:00:00.345, 00:00:00.567 and 00:00:00.842 clearly lie on the new-day-side of midnight, but would be shortened to "00:00:00" for display purposes. Likewise, 23:59:59:899 lies on the old-day-side of midnight. So midnight itself is an infinitely short time span between the days that you will never hit in practice.

  • This is one time it's important to call out the difference between theory and 'alleged' practice: In practice a user typing a date/time could barely be bothered to type the seconds; let alone milliseconds. In practice a timing device that determines the time of an event might not support milliseconds. In practice even if a timing device does support milliseconds, there's no guarantee the storage format doesn't round/truncate a portion of the time for some reason. Commented Feb 27, 2017 at 9:48

This is a similar problem to calculating differences between angles using circular geometry, where for example, 0 degrees and 360 degrees (and 720 degrees, etc) are all the same. So what is the difference between 350 degrees and 10 degrees?

Answer: it depends on which way around you want to measure it - it might be 20 degrees or 340 degrees. But doing the calculation for angular differences is actually quite messy. Time difference calcs are similarly messy unless you convert to an internal form that makes plain addition and subtraction operate conventionally. Or you use a modern class library that magically hides it all away from you (and thus never teaches anybody about the actual details).

  • in both cases, you specify only one way round the clock (or circle) as 'positive'
    – HorusKol
    Commented May 12, 2011 at 0:14
  • True. However, writing the code to do the calc and get it right every time does require a little thought. Commented May 12, 2011 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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