tags:

views:

60

answers:

1

I have a Delphi application which reads data from an excel spreadsheet using code similar to the following:

procedure TForm1.Button1Click(Sender: TObject);
var
  xlApp, xlWorkBook, xlWorkSheet, arr: Variant;
begin
  xlApp := CreateOLEObject('Excel.Application');
  xlApp.Visible := False;

  xlWorkBook := xlApp.Workbooks.Open('C:\Temp\Book1.xlsx');
  xlWorkSheet := xlApp.WorkSheets[1];
  arr := xlWorksheet.Range['E2:E2'].Value;
  xlApp.Quit;
end;

The value stored in the spreadsheet in cell E2:E2 is 10/01/1900 (dd/mm/yyyy). However, the value being returned is the 09/01/1900, ie the day before. Why is this happening as when it seems to be working correctly for all dates in other years from 1900 onwards?

+5  A: 

Pete, this problem is an old bug of excel, because excel incorrectly assumes that the year 1900 is a leap year. so all the dates between 01-01-1900 and 29-02-1900 are affected by this bug.

check these links for more info

RRUZ