Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A twist on age calculation.
Message
De
04/01/2005 10:38:23
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/01/2005 10:36:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
00973330
Message ID:
00974083
Vues:
28
>>A new version of Age Calculator is now available for download (ID #25738). This version gives the expected result in the case described below.
>
>Sorry,
>you have a general problem when .nDays = 0
>
>.CalculateAge({^1996/6/30} ,  {^2003/9/29 })
>Observed 7 , 3,  0
>Expected 7 , 2,  30
>
>
>Fabio

Fabio,
I already sent an age calculation that returns those expected dates:)
Here is it shortenehed:
Define Class AgeCalculator As Custom
  Years = 0
  Months = 0
  Days = 0

  Procedure CalcAge
    Lparameters tdBirth, tdTarget
    Local ldTemp, ldBirth, lnDrop
    If m.tdBirth > m.tdTarget
      ldTemp   = m.tdTarget
      tdTarget = m.tdBirth
      tdBirth  = m.ldTemp
    Endif

    ldBirth = Date(Year(m.tdTarget),Month(m.tdBirth),Day(m.tdBirth))
    lnDrop = 0
    If Empty(m.ldBirth) && leap case
      ldBirth = Date(Year(m.tdTarget),3,1)
      lnDrop = Iif(Month(m.tdTarget)<=2,0,1)
    Endif
    With This
      .Years = Year(m.tdTarget) - Year(m.tdBirth) - ;
        (Iif(m.ldBirth > m.tdTarget,1,0))
      .Months = (Month(m.tdTarget) - Month(m.tdBirth) + 12 - ;
        (Iif(Day(m.tdBirth)>Day(m.tdTarget),1,0)))%12
      ldTemp = Date( Year(m.tdBirth) + .Years, Month(m.tdBirth), Day(m.tdBirth) )
      If Empty(ldTemp)
        ldTemp = Date( Year(m.tdBirth) + .Years, Month(m.tdBirth), Day(m.tdBirth-1) )
      Endif
      .Days = m.tdTarget - Gomonth(m.ldTemp,.Months) - m.lnDrop
    Endwith
  Endproc
enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform