حصر السن وحسابه
#2
وعليكم السلام ورحمة الله وبركاته
يمكنك حساب سن المترشح يوم إجراء المسابقة، ثم فحصه وفقا لشرط المشاركة
حساب سن المترشح ليس أكثر من الفرق بين تاريخين، مثال:
كود :
var BirthDate: TDate; Age: double; begin BirthDate := StrToDate('10/10/1980'); Age := Now - BirthDate; ShowMessage(FloatToStr(Trunc(age / 356)));
بشكل أفضل (كود Simon Grossenbacher ):
PHP كود :
function CalculateAge(Birthday, CurrentDate: TDate): Integer;
var
  
Month, Day, Year, CurrentYear, CurrentMonth, CurrentDay: Word;
begin
  DecodeDate
(Birthday, Year, Month, Day);
  
DecodeDate(CurrentDate, CurrentYear, CurrentMonth, CurrentDay);

  if (
Year = CurrentYear) and (Month = CurrentMonth) and (Day = CurrentDay) then
  begin
    Result 
:= 0;
  
end
  
else
  
begin
    Result 
:= CurrentYear - Year;
    if (
Month > CurrentMonth) then
      Dec
(Result)
    else
    
begin
      
if Month = CurrentMonth then
        
if (Day > CurrentDay) then
          Dec
(Result);
    
end;
  
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1
.Caption := Format('Your age is %d', [CalculateAge(StrToDate('01.01.1903'), Date)]);
end; 

طريقة أخرى أيضا يمكنك إنشاء قاعدة بيانات صغيرة، حيث سن المترشح حقل حسابي باستخدام SQL
PHP كود :
SELECT Employees.FirstName, Employees.LastName, Employees.BirthDate, Year(Date())-Year([BirthDate]) AS Age
FROM Employees 
بالتوفيق.
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...
الرد


الردود في هذا الموضوع
حصر السن وحسابه - بواسطة Bachirsoft - 31-10-2012, 07:00 PM
حصر السن وحسابه - بواسطة Najy Ibraheem - 31-10-2012, 09:26 PM
حصر السن وحسابه - بواسطة Bachirsoft - 01-11-2012, 05:56 AM
حصر السن وحسابه - بواسطة format82 - 01-11-2012, 07:18 PM
حصر السن وحسابه - بواسطة format82 - 01-11-2012, 07:31 PM
حصر السن وحسابه - بواسطة Bachirsoft - 08-11-2012, 08:55 PM
حصر السن وحسابه - بواسطة kachwahed - 31-10-2012, 08:41 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم