Bad conversion from EndOfMonth (date) to Variant value

I have a TDateTime (which I get as a result from EndOfTheMonth(date) ) to a variant. The result is erroneously rounded. Let's look at an 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 this a designed behavior? How to get around this?

+6
source share
1 answer
 ShowMessage(DateTimeToStr(data) + ' vs ' + DateTimeToStr(VarToDateTime(V))); 

Update: I think the problem is that the last millisecond of the month is very close to 0:00:00 the next day, that is, the TDateTime (mainly double ) is very close to an integer (for example, 41029.9999999884 very close to 41029 ), and therefore, the VarToStr function accepts decimal values ​​as numeric fuses.

+6
source

Source: https://habr.com/ru/post/912491/


All Articles