I am trying to calculate daysbetween difference between two dates in the grid.
This kind’a works but produces at first strange result:
This is Oncalculate fields event of the TEMP table:
TEMP.FieldByName('DAYS').asstring := IntToStr(Daysbetween(TEMP.FieldByName('BIV_OD').AsDateTime,TEMP.FieldByName('BIV_DO').AsDateTime));
BIV_OD and BIV_DO are date fields (ie. like … Date_From – Date-to)
When I select the first date in the grid (BIV_OD) ,my DAYS field at first show 40731 (??)
Then when i input the second date everything works ok.
Why is that ?
That’s what you asked for…
Delphi stores dates as the number of days since 31/12/1899 so when you write the first date you are doing 40731(The number of days since 31/12/1899) – 0 since you haven’t yet entered a second date.
The solution would be not to calculate the field unless both dates are filled in.
Although I’d set the grid column to have a data type of integer.