Months in 2 dates

zwaz

New Member
Joined
Jun 15, 2008
Messages
3
Hi

Is there a way to identify the number od days between 2 dates and the month

Example

01/01/08 - 15/03/08

Answer = Jan = 31 days, Feb - 29 days, March = 15 days

Any help would be greatly appreciated
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
This will give you a value for each of the 12 months if entered in a cell and copied down 12 cells in a column

=SUMPRODUCT(--(MONTH(ROW(INDIRECT($A$1&":"&$B$1)))=ROW(A1)))

If you want it in a row, change ROW to COLUMN.
 
Upvote 0
Try the following codes:
Code:
Sub macro1()
MsgBox getall(#1/1/2008#, #9/15/2008#)
End Sub
Function getall(ByVal d1 As Date, ByVal d2 As Date) As String
Dim s() As String, i As Long
ReDim s(Month(d1) To Month(d2))
For i = LBound(s) To UBound(s)
s(i) = Format(DateSerial(Year(d1), i + 1, 0), "mmm=d") & " days"
Next
s(LBound(s)) = Format(d1, "mmm=") & DateSerial(Year(d1), Month(d1) + 1, 0) - d1 & " days"
s(UBound(s)) = Format(d2, "mmm=d") & " days"
getall = Join(s, ",")
End Function

Regards
Northwolves
 
Upvote 0
If your start date is in A2 and end date in B2 then you could list the 1st of each month in D1 across, e.g. D1 has 1-Jan-2008, E1 has 1-Feb-2008, F1 has 1-March-2008, extend as far as necessary [format these dates as mmm-yy if you wish]

Then in D2 copied across

=MAX(0,MIN($B2,D$1+32-DAY(D$1+32))-MAX($A2,D$1)+1)
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,593
Members
449,038
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top