On 7/25/2012 4:45 PM, Fred Taylor wrote:
> What constitutes a month? Is 2012-06-30 to 2012-07-01 one month or two?
> And how would your example be 13?
Hi Fred,
Sorry...forgot to say "disregard the day in the month." Here's what I
came up with. It's a bit verbose but it's for clarity's sake:
FUNCTION CountMonths(tdStart as Date, tdEnd as Date) as Integer
LOCAL liNumMonths as Integer, liStartYear as Integer, liEndYear
as
Integer, liStartMonth as Integer, liEndMonth as Integer
IF tdEnd >= tdStart THEN
liStartYear = YEAR(tdStart)
liEndYear = YEAR(tdEnd)
liStartMonth = MONTH(tdStart)
liEndMonth = MONTH(tdEnd)
IF liStartMonth >= liEndMonth THEN && take 12 months
from year for
date math
liEndYear = liEndYear - 1
liEndMonth = liEndMonth + 12
ENDIF
liNumMonths = ((liEndYear - liStartYear) * 12) +
(liEndMonth -
liStartMonth) + 1 && last +1 is to include the month you're in
ELSE && invalid entry...start shouldn't be later than end
liNumMonths = -1
ENDIF && tdEnd >= tdStart
RETURN liNumMonths
ENDFUNC && CountMonths(tdStart as Date, tdEnd as Date) as Integer
--
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.