vb6: date calculation

I'm programming with VB6.  I would like to know if there any convenient functions can performing date calculations and conversion.  (e.g. I want to get the last date of a specific month, ie. i can get 28 when i specified Feb, 1999, i can get 30 when i specified Nov, 1999.)

I found that MSDN (the help in Visual Studo 98 is hard to use), I have to install large size of useless files.  I've tried to look up the help but i just found unrelated topics.

Please give me a hand, tks!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
If you paste the following function in a form somewhere, call it using

value = GetLastDay("4","1999")

for example it will return


If you change the format string to just "DD" it will return 30 which is the last day of the month selected.

Private Function GetLastDay(strMonth, strYear)
    Dim dtNew As Date
    intMonth = Val(strMonth)
    intYear = Val(strYear)
    If intMonth > 12 Or intMonth < 1 Then
        GetLastDay = "Invalid Month"
        Exit Function
    End If
    If intMonth = 12 Then
        intMonth = 1
        intYear = intYear + 1
        intMonth = intMonth + 1
    End If
    dtNew = CDate("1/" & CStr(intMonth) & "/" & CStr(intYear)) - 1
    GetLastDay = Format(dtNew, "MM/DD/YYYY")
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This function will return the date of the last day of a month based on passing it a valid date string such as: "mm/dd/yy" or "mm/dd/yyyy" or "mm-dd-yy" or "mm-dd-yyyy"



Function LastDayOfMonth(UseDate As String) As Date
    Dim lDate As Date
    Dim lMonth As String
    lDate = UseDate
    lMonth = Format(lDate, "mm")
        lDate = lDate + 1
        If Not Format(lDate, "mm") = lMonth Then
            lDate = lDate - 1
            Exit Do
        End If
    LastDayOfMonth = lDate
End Function

Private Function dLastDay(dDateInMonth) As Date

    dLastDay = DateAdd("m", 1, dDateInMonth + 1 - _
    Day(dDateInMonth)) - 1

End Function

You'll find better answers at EE than at MSDN!
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

chuyanAuthor Commented:
tks for all experts!!

deighton, what is EE? how can i install it? is it included in visual studio 98?
chuyan, You'ew using EE right now!!!

chuyanAuthor Commented:
actually by MSDN, i just mean the "html help" included in visual studio 98,
i found it is poorly designed, not as convenient as the old help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.