Board index » delphi » Bug: Date - Field.AsDateTime not correct

Bug: Date - Field.AsDateTime not correct

I have a big problem with date function and Date field operation.
I need to calculate how old is a people with the birthday and the actual
date, and put it in a integer calculated field.

In my case, i do

Var
    Year,Month,Day:word;

Begin
.
.
    Decode(Date-BirthDay.AsDateTime,Year,Month,Day)
    OldField.value:=Year;
.
.
End;

P.e., if the date is 10 january 2000, and birthday is 19 may 1980, the
result is    1920

I solve it decoding both date and calculting with both years variable. But
it's a big bug.

Alexandre

 

Re:Bug: Date - Field.AsDateTime not correct


It is not actually a bug. What you have done by saying
Date-BirthDay.AsDateTime is get the number of days between the two dates
(approx 7600). If you then attempt to use this as a date you are saying that
the value in date variable (~7600) is x days after 01/01/1900 which is 1920.

To test this do

ShowMessage(DateToStr( StrToDate(01/01/1999) - StrToDate(01/01/1998)))

which will give you '30/12/1900'

Alexandre Duran Mertens <csdesarro...@nostracom.com> wrote in message
news:85hj7i$5dc18@bornews.borland.com...

Quote
> I have a big problem with date function and Date field operation.
> I need to calculate how old is a people with the birthday and the actual
> date, and put it in a integer calculated field.

> In my case, i do

> Var
>     Year,Month,Day:word;

> Begin
> .
> .
>     Decode(Date-BirthDay.AsDateTime,Year,Month,Day)
>     OldField.value:=Year;
> .
> .
> End;

> P.e., if the date is 10 january 2000, and birthday is 19 may 1980, the
> result is    1920

> I solve it decoding both date and calculting with both years variable. But
> it's a big bug.

> Alexandre

Other Threads