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!
chuyanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TimCotteeConnect With a Mentor Commented:
If you paste the following function in a form somewhere, call it using

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

for example it will return

04/30/1999

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
    Else
        intMonth = intMonth + 1
    End If
    dtNew = CDate("1/" & CStr(intMonth) & "/" & CStr(intYear)) - 1
    GetLastDay = Format(dtNew, "MM/DD/YYYY")
End Function
0
 
mcriderCommented:
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"


Cheers!

THE CODE:


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



0
 
deightonCommented:
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!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
chuyanAuthor Commented:
tks for all experts!!

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

Cheers!
0
 
chuyanAuthor Commented:
ic......
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.

right?
0
All Courses

From novice to tech pro — start learning today.