Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ditch storing dates in gregorian ages ago. I store dates as an 32bit integer (sort of like a Julian date). So the date is composed as (Year * 1000) + DOY (DOY is day of year). I.e. - 2009001 Is Jan 1 2009 - 2009365 is Dec 31 2009</p> <p>My date class of course provides methods for getting the Year, Month and Day, adding, subtracting, incrementing and decrementing, comparing, getting the number of days between dates etc..</p> <p>For date and time, I use 64bit float where the integer portion of the real number is the same as integer (Julian like) dates described above, and the fraction represents the time in fraction of a day. </p> <p>I.e. </p> <ul> <li>2009001.04166666666~ is Jan 1,2009 1:00am</li> <li>2009001.06249999999~ is Jan 1,2009 1:30am</li> <li>2009001.95833333333~ is Jan 1,2009 11:00pm</li> </ul> <p>If you only need minute accuracy, you can use 32bit float for date and time but you can't adequately accurately store seconds and milliseconds.</p> <p>The advantages of storing dates (and time) in this manner are:</p> <ul> <li><p>You only need 8bytes to represent the data and time as compared to 28bytes (assuming 32bit integers) used by the DateTime class in the question.</p></li> <li><p>Compared with dates stored as seconds from an epoch, when looking at the number (for example in the debugger) you can more or less identify from the number the year and the day of year, and the approximate time of day (to get the hour, minute, second after midnight simply mulitply by 24, 1440, 86400 respectively).</p></li> <li><p>Comparing dates is trivial, simply compare the numbers (A single CPU operation compared to the several it would take for the example DateTime).</p></li> <li><p>Fewer comparison operations to do date arithmetic.</p></li> </ul> <p>The disadvange of this (for time time) is a slight loss of accuracy (this is practically a mute point) and you have to do some simple rounding to get nice integer values when convering to integer values of hours minutes and seconds.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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