Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Month Calculations
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00498208
Message ID:
00498301
Vues:
12
>We need to determine exactly how many months difference there is between 2 dates in VFP
>Example:
>01/01/2001 - 03/01/2001 = 3 months
>
>We are currently trying the following:
>x=date1 (01/01/2001)
>y=date2 (03/01/2001)
>z=y - x
>b=z/365*12
>c=b +1
>
>result=int(c)
>
>The problem we are running into is short months
>
>
>Larry
****************************
Hi Larry, may be it help you:
Define class periodofwork as custom
  Function recstag
  Lparameters pdBeg,pdEnd,pnDn,pnMon,pnYea
  store 0 to pnDn,pnMon,pnYea
  do case
    case pdBeg=pdEnd.or.(empty(pdBeg).or.empty(pdEnd)).or.pdBeg>pdEnd
    case year(pdbeg)=year(pdEnd).and.month(pdBeg)=month(pdEnd)
      pnDn=pdEnd-pdBeg
    case year(pdbeg)=year(pdEnd)
      pnMon=month(pdEnd)-month(PdBeg)-1
      do case
        case day(pdBeg)>day(pdEnd)
          ldLow=date(year(gomonth(pdBeg,1)),month(gomonth(pdBeg,1)),1)-pdBeg-1
          pnDn=(ldLow)+day(pdEnd)
        case day(pdBeg)<day(pdEnd)
          pnDn=day(pdEnd)-day(pdBeg)
          pnMon=pnMon+1            
        case day(pdBeg)=day(pdEnd)
          pnMon=pnMon+1  
	  endcase
	case day(pdbeg)=day(pdEnd).and.month(pdBeg)=month(pdEnd).and.between(year(pdEnd)-year(pdBeg),364,367)
	  pnYea=year(pdEnd)-year(pdBeg)
	case pdEnd-pdBeg<365
	  pnMon=12-month(PdBeg)+month(pdEnd)-1
	  do case
        case day(pdBeg)>day(pdEnd)
          ldLow=date(year(gomonth(pdBeg,1)),month(gomonth(pdBeg,1)),1)-pdBeg-1
          pnDn=(ldLow)+day(pdEnd)
        case day(pdBeg)<day(pdEnd)
          pnDn=day(pdEnd)-day(pdBeg)
          pnMon=pnMon+1            
        case day(pdBeg)=day(pdEnd)
          pnMon=pnMon+1  
	  endcase
	otherwise
	  pnYea=year(pdEnd)-year(pdBeg)-1
	  pnMon=12-month(PdBeg)+month(pdEnd)-1
	  do case
        case day(pdBeg)>day(pdEnd)
          ldLow=date(year(gomonth(pdBeg,1)),month(gomonth(pdBeg,1)),1)-pdBeg-1
          pnDn=(ldLow)+day(pdEnd)
        case day(pdBeg)<day(pdEnd)
          pnDn=day(pdEnd)-day(pdBeg)
          pnMon=pnMon+1            
        case day(pdBeg)=day(pdEnd)
          pnMon=pnMon+1  
	  endcase	  
	  if pnMon>=12  && we can do it because year has 12 months
	    pnMon=pnMon-12
	    pnYea=pnYea+1
	  endif
  endcase
  endfunc
Enddefine
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform