Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of days per month between 2 dates

Status
Not open for further replies.

apestaart

Technical User
Feb 5, 2004
107
NL
Hi,
I need to caculate the number of days between two dates for all the month seperately.
so beginning date is 3 may and ending date is 5 july should give me for may: 28, juni: 30 and july: 5. How can I do that.
Regards apestaart
 




Hi,

calculate the difference between the two dates.

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 



Sorry, did not completely read your question.

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 


Code:
Function DaysPerMonthDIFF(d1 As Date, d2 As Date)
    Dim d As Date, dEND As Date
    d = d1
    Do
        dEND = DateSerial(Year(d), Month(d) + 1, 0)
        If dEND > d2 Then
            DaysPerMonthDIFF = DaysPerMonthDIFF & Format(d, "mmm") & ":" & d2 - d + 1 & ","
            Exit Do
        Else
            DaysPerMonthDIFF = DaysPerMonthDIFF & Format(d, "mmm") & ":" & dEND - d + 1 & ","
        End If
        d = dEND + 1
    Loop
    DaysPerMonthDIFF = Left(DaysPerMonthDIFF, Len(DaysPerMonthDIFF) - 1)
End Function

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
Hi Skip,
Thanks for the respons, but it is not what I asked.
May 3th and July 5th are just examples.
Could also be Jan 10th to Aug 9th. Then I should get 8 values. 21 for January, 28 for febr, 30 for March..etc....and 9 for August.
In my first example the function should five me 3 values.
I hoop I was clear this time.
Regards,
Apestaart
 




did you try it???

Here's what I get (don't forget leap year!!!!!)...
[tt]
Jan:22,Feb:29,Mar:31,Apr:30,May:31,Jun:30,Jul:31,Aug:9
[/tt]

Skip,
[sub]
[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue][/sub]
 
Sorry Skip,
I thougth I understood, but I did not.
This code realy helps me. I have to study to understand it.
Thank you for your quick response.
Best regards,
Apestaart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top