Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Jamie Osborn
  Where is Jamie Osborn?
 Melbourne
 Australia
 Jamie Osborn
 To: manute97 perquin
  Where is manute97 perquin?
 Monte Plata
 Dominican Republic
 manute97 perquin
 Tags
Subject: RE: calculate age
Thread ID: 16190 Message ID: 16192 # Views: 2 # Ratings: 0
Version: Unknown Category: General VFP Topics
Date: Friday, October 11, 2002 3:20:36 AM         
   


> i like calculate the age from any players, how can to do?
> i have a text box thisform.fechanac.value
> and have other textbox thisform.age.value
> the result would be Example "23 year,11 month, and 19 days.
> mp200


This is from an MSDN article :

nTotalDays = BetweenDates (dBirthDate, Date (), @nYears @nMonths, @nDays)

 Function BetweenDates 
*-------- ------------
 LParameters pStartDate, pEndDate, pYears, pMonths, pDays
 Local       dStartDate, dEndDate, dPreCmpDate

 dPreCmpDate = {}

 dStartDate  = Min (pStartDate, pEndDate) && Just in case you forget parameters order :)
 dEndDate    = Max (pStartDate, pEndDate)

 pYears      = 0
 pMonths     = 0
 pDays       = 0

 dEndOfMonth = CtoD (AllTrim (Str (Month (dEndDate)))  + '/' + "01" + '/' + ;
                     AllTrim (Str (Year  (dEndDate)))) - 1

 If Month (dStartDate) <= Month (dEndDate)

    pYears = Year (dEndDate) - Year (dStartDate)

    If Day (dStartDate) <= Day (dEndDate)
       pMonths = Month (dEndDate) - Month (dStartDate)
       pDays   = Day   (dEndDate) - Day   (dStartDate)
    else
       If Month (dStartDate) = Month (dEndDate)
          pYears = pYears - 1
       endif
       pMonths = Mod (Month (dEndDate) - Month (dStartDate) - 1 + 12, 12)
       pDays = dEndOfMonth - dPreCmpDate + Day (dEndDate)
   endif

 Else

   pYears = Year (dEndDate) - Year (dStartDate) - 1

   If Day (dStartDate) > Day (dEndDate)
      pMonths = Month (dEndDate) - Month (dStartDate) + 12 - 1
      pDays   = dEndOfMonth - dPreCmpDate + Day (dEndDate)
   else
      pMonths = Month (dEndDate) - Month (dStartDate) + 12
      pDays   = Day   (dEndDate) - Day   (dStartDate)
   endif

 EndIf

 Return (pEndDate - pStartDate)

 EndFunc                        &&  of BetweenDates

Cheers,
Jamie
jamie.osborn@foxite.com

ENTIRE THREAD

calculate age Posted by manute97 perquin @ 10/11/2002 2:51:15 AM
RE: calculate age Posted by Jamie Osborn @ 10/11/2002 3:20:36 AM