number of Full Months between dates & partial Days calculation

S

Silvio

Hello, I need help in write 3 piece of code in VBA to calculate the following:
1. The number of full months between two dates
2. The number of days to the end of the same month if the start date is NOT
the 1st of the month
3. The number of days from the beginning of the End Date if the end date is
not the last day of the month
Example:
Start Date: 9/18/09
End Date: 12/15/09

Result:
Total of Full Month: 2 (only October and November are full between the two
dates above)
Start Days: 13 (Between 9/18/09 included to 9/30/09 included)
Ending Days: 15 (Between 12/1/09 to 12/15/09)

Thank you,
Silvio
 
D

Douglas J. Steele

The number of full months would be

DateDiff("m", StartDate, EndDate) - IIf(Day(EndDate) < Day(StartDate), 1, 0)

The number of days to the end of the month for the start date is

Day(DateSerial(Year(StartDate), Month(StartDate) + 1, 0) - Day(StartDate)

(depending on your definition, you may want to add 1 to that)

The number of days from the beginning of the month for the end date is

Day(EndDate)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top