Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad conversion from EndOfTheMonth(date) to Variant value

I have a TDateTime value (that I get as result from EndOfTheMonth(date)) to a variant type. The result is wrongly rounded. Let's have a look at example:

  data := EndOfTheMonth(date);
  V := data;
  ShowMessage(DateTimeToStr(data) + ' vs ' + VarToStr(V));
 // output is
 // data = 2012-01-31 23:59:59
 // v    = 2012-02-01            // why next day?

Is it designed behaviour? How to work around this?

like image 495
JustMe Avatar asked Apr 05 '12 11:04

JustMe


1 Answers

ShowMessage(DateTimeToStr(data) + ' vs ' + DateTimeToStr(VarToDateTime(V)));

Update: I would guess the problem is that the last millisecond of the month is very close to 0:00:00 the next day, that is, the TDateTime value (which is basically a double) is very close to an integer (e.g. 41029.9999999884 is very close to 41029) and so the VarToStr function assumes the decimals to be numerical fuzz.

like image 188
Andreas Rejbrand Avatar answered Nov 14 '22 19:11

Andreas Rejbrand