Here's a program that I posted last year. It takes a person's birthday and today's date as input, then computes the person's age in days. That's the opposite of what you are trying to do, however, you may find some of the functions and procedures useful. Sorry I can't do more right now but it's late and I need to get to bed.
Program Days ;
Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;
Function IsLeap (Year : LongInt) : Boolean ;
{
a year is a leap year IF it's divisible by 4
UNLESS it's also divisible by 100, then it's
a leap year ONLY if it divisible by 400
}
begin
if Year DIV 4 = 0 then begin
if Year DIV 100 = 0 then begin
if Year DIV 400 = 0 then
IsLeap := TRUE
else
IsLeap := FALSE
end
else
IsLeap := TRUE
end
else
IsLeap := FALSE
end ;
Function DaysPriorToThisYear (Year : LongInt) : LongInt ;
Var
i, Count : LongInt ;
begin
Count := 0 ;
for i := 1 to Year - 1 do
if IsLeap(i) then
Count := Count + 366
else
Count := Count + 365 ;
DaysPriorToThisYear := Count
end ;
Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;
CONST
MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
= ((31,28,31,30,31,30,31,31,30,31,30,31),
(31,29,31,30,31,30,31,31,30,31,30,31)) ;
Var
i, Count : LongInt ;
begin
Count := 0 ;
for i := 1 to Month - 1 do
if IsLeap(Year) then
Count := Count + MonthDays[TRUE, i]
else
Count := Count + MonthDays[FALSE, i] ;
DaysPriorToThisMonth := Count
end ;
begin
Julian := DaysPriorToThisYear(Year)
+ DaysPriorToThisMonth(Year,Month)
+ Day
end ;
Var
Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;
begin
Write ('Enter year of birth: ') ; ReadLn (Year0) ;
Write ('Enter month of birth: ') ; ReadLn (Month0) ;
Write ('Enter day of birth: ') ; ReadLn (Day0) ;
WriteLn ;
Write ('Enter today''s year: ') ; ReadLn (Year1) ;
Write ('Enter today''s month: ') ; ReadLn (Month1) ;
Write ('Enter today''s day: ') ; ReadLn (Day1) ;
BirthDay := Julian (Year0, Month0, Day0) ;
Today := Julian (Year1, Month1, Day1) ;
WriteLn (Today :10) ;
WriteLn (Birthday:10) ;
WriteLn ('The person is ', Today - BirthDay, ' days old.')
end.