Evo jos jedna procedura koja racuna godine, mesece i dane.
Po autoru uzima u obzir i prestupne godine.
POmocu ove funkcije dobices godine, mesece i dane izmedu danasnjeg dana ili nekog drugo koji ti treba i 26.06.2008.
Iz moje procedure izvuci ces godine, mesece i dane radnog staza do 26.06.2008.
i na kraju ces da ih saberes.
Ukoliko broj dana prelazi 30 ili 31? (Moras da pitas nekog pravnika kako se racuna staz)
Code:
procedure YearsMonthsWeeksDaysBetween(DateFrom, DateTo : TDate; Var YearsGap, MonthsGap, WeeksGap, DaysGap : Word);
var
DaysNumber,DaysCounter,DaysInAMonthCounter: Word;
YearsCount, MonthsCount, WeeksCount, DaysCount,DaysInCurrentMonth: Word;
TempDate : TDate;
begin
//Init Vars.
// Respresents: YearsGap, MonthsGap, WeeksGap, DaysGap
YearsCount:=0; MonthsCount:=0; WeeksCount:=0; DaysCount:=0;
// Represents: The Days gap by two dates (In Days only) and Days Counter.
DaysCounter:=0; DaysNumber:=DaysBetween(DateFrom, DateTo);
// Represents: The current Month's number of days and Days counter (per a month)
DaysInCurrentMonth:=0; DaysInAMonthCounter:=0;
// Copy the DateFrom parameter for farther calculations
TempDate:=DateFrom;
// Update the number of days in current month
DaysInCurrentMonth:=DaysInMonth(TempDate);
// Actual Job -- Check on each day.
While DaysCounter < DaysNumber do
Begin
Inc(DaysCounter);
Inc(DaysInAMonthCounter);
Inc(DaysCount);
If DaysCount=7 Then
Begin
Inc(WeeksCount);
DaysCount:=0;
End;
// If you reach the end of a month, based on the number
// of days of the current month then
If (DaysInAMonthCounter = DaysInCurrentMonth) Then
Begin
Inc(MonthsCount);
WeeksCount:=0;
DaysCount:=0;
If MonthsCount=12 then
Begin
Inc(YearsCount);
MonthsCount:=0;
End;
// Add a month, based on the month's number of days, to DateFrom
TempDate:=TempDate+DaysInCurrentMonth;
// Calculate the number of days of the next month
DaysInCurrentMonth:=DaysInMonth(TempDate);
// Start coung Month's days all over again.
DaysInAMonthCounter:=0;
End;
End;
End;
[Ovu poruku je menjao Milan Milosevic dana 09.07.2015. u 06:04 GMT+1]