Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to calculate the age based on the date of birth Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
18-Oct-02
Category
Algorithm
Language
Delphi 2.x
Views
142
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to calculate the age based on the date of birth.

Answer:

Solve 1:

1   { BrthDate:  Date of birth }
2   
3   function TFFuncs.CalcAge(brthdate: TDateTime): Integer;
4   var
5     month, day, year, bmonth, bday, byear: word;
6   begin
7     DecodeDate(BrthDate, byear, bmonth, bday);
8     if bmonth = 0 then
9       result := 0
10    else
11    begin
12      DecodeDate(Date, year, month, day);
13      result := year - byear;
14      if (100 * month + day) < (100 * bmonth + bday) then
15        result := result - 1;
16    end;
17  end;



Solve 2:
18  
19  procedure TForm1.Button1Click(Sender: TObject);
20  var
21    Month, Day, Year, CurrentMonth, CurrentDay, CurrentYear: word;
22    Age: integer;
23  begin
24    DecodeDate(DateTimePicker1.Date, Year, Month, Day);
25    DecodeDate(Date, CurrentYear, CurrentMonth, CurrentDay);
26    if (Year = CurrentYear) and (Month = CurrentMonth) and (Day = CurrentDay) then
27      Age := 0
28    else
29    begin
30      Age := CurrentYear - Year;
31      if (Month > CurrentMonth) then
32        dec(Age)
33      else if Month = CurrentMonth then
34        if (Day > CurrentDay) then
35          dec(Age);
36    end;
37    Label1.Caption := IntToStr(Age);
38  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC