Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
wait wait, where is your location? what date is it now? 08 or 07? –  Phelios Apr 8 '11 at 1:30
    
sry - made it clearer that I'm already on the 8th (I'm in Adelaide, SA) –  HorusKol Apr 8 '11 at 2:37
1  
So you are basically asking is 00:00:00 smaller or larger than 10:45:00? –  Loki Astari May 11 '11 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 May 11 '11 at 13:12
    
In some contexts 24:00:00 is used to describe midnight at the end of the day. –  CodesInChaos Feb 23 '13 at 15:41
show 1 more comment

3 Answers

up vote 17 down vote accepted

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

share|improve this answer
2  
Yes, the day rolls over at midnight, which is 00:00:00. –  quickly_now Apr 8 '11 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. May 11 '11 at 13:42
add comment

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.

share|improve this answer
add comment

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).

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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