Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time span calculation help!!! its urgent

Status
Not open for further replies.

rati

Programmer
Mar 27, 2003
1
NZ
i have a problem for time span calculation.

can u please tell me how to do the following problem.

The program is required to read data from a text file.FOr each record in the file calculate the time elapsed (in years and days) between the start and end dates,and display the information.If the end date is not specified,the time elapsed to the present day must be displayed.
If either date is not valid or if the end date is before the start date message "ERROR" must be displayed.

consider the leap year.
the earliest date is 1st January 1900 and the latest 31st Dec 2020

Please help me i'm just 18yrs old n confused..its urgent please..
 
Something like this (hope you can write the part that would read the dates from file):
Code:
function TimeToMonthsAndDays(StartDate, EndDate : TDateTime): String;
var
  MonthsCount  : Integer;
begin
  Result := '';
  if (StartDate < EndDate)then
  begin
    ShowMessage('Error');
    Exit;
  end
  MonthsCount := 0;
  while (IncMonth(StartDate, 1) <= EndDate) do
  begin
    StartDate := IncMonth(StartDate, 1);
    Inc(MonthsCount);
  end;
  Result := Format('%d Y, %d M, %d D', [MonthsCount div 12, MonthsCount mod 12, Trunc(DateTo - DateFrom)]);
end;
HTH

--- markus

[...We are all gods in our own digital worlds...]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top