Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Days between months not dates
Message
De
10/12/2009 09:48:49
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01436643
Message ID:
01438390
Vues:
61
Hi Zaheed and Naomi,

Cetin's AgeCalculator is not good. E.g. it does not produce month's birthday if a month has less than 31 days and a person was born on 31.
Another issue is when a person was born on Feb 29 it is buggy :

dt1= 02/29/2004
dt2= 03/29/2005
gives: 1/ 1/-1

Have a look at my function AgeYMD, message ID: 1353806.

Regards,
Sergey

>Hi Zaheed,
>
>Not sure, what did you want, but take a look at
>
>Re: What is best way to calculate age Thread #1155605 Message #1155606
>
>and
>
>http://berezniker.com/content/pages/visual-foxpro/birthday-query-vfp
>
>>Hi,
>>
>>I found this program below which works except the variable endofmonth gives me the wrong number of days. It gives me 18 days when it should give me 0 years, 11 months and 28 days but I get 18 days.
>>Thanks in advance
>>
>>
>>* BTWNDATE.PRG
>>
>>startdate = {19/02/2008} && Thisform.dStart.value 
>>enddate =   {18/02/2009}   &&Thisform.dend.value 
>>
>>
>>IF startdate ‘&greaterthan’ enddate
>>	WAIT WINDOW "Start date must " + CHR(13) ;
>>		+ "be earlier than End date"
>>	RETURN
>>ENDIF
>>
>>PRIVATE  precmpdate, vyears, vmonths, vdays
>>precmpdate={}
>>vyears=0
>>vmonths=0
>>vdays=0
>>nTotdays = 0
>>* Calculate:
>>*     endofmonth is the last day of month prior to month of enddate
>>*
>>endofmonth = CTOD(ALLTRIM(STR(MONTH(enddate))) + '/' + "01" + '/' + ;
>>	ALLTRIM(STR(YEAR(enddate)))) - 1
>>*
>>IF MONTH(startdate) ‘&lessthan’= MONTH(enddate)
>>
>>	vyears = YEAR(enddate) - YEAR(startdate)
>>	IF DAY(startdate) ‘&lessthan’= DAY(enddate)
>>		vmonths = MONTH(enddate) - MONTH(startdate)
>>		vdays = DAY(enddate) - DAY(startdate)
>>		nTotdays = (enddate) - (startdate)
>>	ELSE
>>		IF MONTH(startdate) = MONTH(enddate)
>>			vyears = vyears - 1
>>		ENDIF
>>		vmonths = MOD(MONTH(enddate) - MONTH(startdate) - 1 + 12, 12)
>>		vdays = endofmonth - precmpdate + DAY(enddate)
>>		nTotdays = (enddate) - (startdate)
>>	ENDIF
>>ELSE
>>	vyears = YEAR(enddate) - YEAR(startdate) - 1
>>	IF DAY(startdate) ‘&greaterthan’ DAY(enddate)
>>		vmonths = MONTH(enddate) - MONTH(startdate) + 12 - 1
>>		vdays = endofmonth - precmpdate + DAY(enddate)
>>		nTotdays = (enddate) - (startdate)
>>	ELSE
>>		vmonths = MONTH(enddate) - MONTH(startdate) + 12
>>		vdays = DAY(enddate) - DAY(startdate)
>>		nTotdays = (enddate) - (startdate)
>>	ENDIF
>>ENDIF
>>Clear
>>
>>= Messagebox('Values are'+  CHR(13) + ;
>>	'  Years:  '  + STR(vyears) + CHR(13) + ;
>>	'  Months: ' + STR(vmonths) + CHR(13) + ;
>>	'  Days:   ' + STR(vdays) + CHR(13) + ;
>>	'  Total number of Days: ' + STR(nTotdays) + CHR(13) + ;
>>	CHR(13) + ;
>>	'  Between ' + DTOC(startdate) + CHR(13) +;
>>	'     and ' + DTOC(enddate))
>>RETURN
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform