Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date Calculation
Message
De
29/03/2004 03:03:44
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
28/03/2004 01:54:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00890235
Message ID:
00890345
Vues:
22
>Hi All,
>
>Is there a sample code that will calculate the number of years, months and days given a total number of days?
>
>Example. 365 days -> 1 year, 0 month and 0 day
>650 days -> 1 year, 9 months & ~11 days
>
>
>TIA

Mathew,
Day part depends on if there is a leap year or not.
oAge = Createobject("age")
oAge.CalcAge({^2004/02/28}, {^2004/02/28}+650)

? oAge.Years, oAge.Months, oAge.Days

oAge.CalcAge({^2001/02/28}, {^2001/02/28}+650)

? oAge.Years, oAge.Months, oAge.Days


Define Class age As Relation
  Years=0
  Months=0
  Days=0
  Procedure CalcAge
  Lparameters tdBirth, tdTarget
  Local ldTemp, ldBirth, lnDrop
  If tdBirth > tdTarget
    ldTemp = tdTarget
    tdTarget = tdBirth
    tdBirth = ldTemp
  Endif
  ldBirth = Date(Year(tdTarget),Month(tdBirth),Day(tdBirth))
  lnDrop = 0
  If Empty(ldBirth) && leap case
    ldBirth = Date(Year(tdTarget),3,1)
    lnDrop = Iif(Month(tdTarget)<=2,0,1)
  Endif
  With This
    .Years = Year(tdTarget) - Year(tdBirth) - (Iif(ldBirth > tdTarget,1,0))
    .Months = (Month(tdTarget) - Month(tdBirth) + 12 - ;
      (Iif(Day(tdBirth)>Day(tdTarget),1,0)))%12
    .Days = tdTarget - Gomonth(tdBirth,.Years*12+.Months) - 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
Répondre
Fil
Voir

Click here to load this message in the networking platform