TDateTime math

Giganews Newsgroups
Subject:TDateTime math
Posted by: Teri Oster
Date:Mon, 31 Aug 2009

I'm using Delphi 2009 (but found same behavior in 2007) and trying to "normalize" an irregular sequence of data readings to a fixed time interval -- in this case, 2 minutes.  I've a variable called *CurrentFixtTime* which is a TDateTime that keeps track of the current 2 minute time on which I'm working.  I increment this using IncMinute (but found same anomaly when using other methods of incrementing the time variable).

Things are fine until I get to *exactly 4210* minutes from the initial value of *CurrentFixtTime* (if starting at 1/1/2004 0:00, occurs at 1/3/2004 22:12).  Instead of 1/3/2004 22:12:00:000, I get 1/3/2004 22:11:59:999.  And when I use FormatDateTime to display using only date and hour/minute (m/d/yyyy h:nn), the value is not rounding up.  I've tried adding 1 millisecond, even 1second, but no good!

I've tried other date ranges -- starting at 12/15/2003 10:10, messes up at 12/18/2003 8:20 (get 8:19 instead);  starting at 12/28/2003 18:22 messes up at 12/31/2003 16:32 (get 16:31 instead).  Same in other years.

What is going on?  Any ideas?

Teri

Replies