Date and Time Useful Functions for VB 6.0
Below is some sample code that I have used in the past that has some useful date and time functions. The code was written in Visual Basic 6.0 but can easily be converted to .Net.
Attribute VB_Name = “TimeDateFunctions”
Public TheYear As Integer, TheMonth As Integer, TheDay As Integer
Public Function LastDayOfMonth(ByVal ADate As Date, PreviousMonth As Integer) As Integer ‘Previous month is an offset of the passed in date to return the last day in a different month
‘For example, if ADate is in February and PreviousMonth is 3, the last day of November will be given
‘This will not go back more than a year, previous month max is 12
Dim CurrentMonth As Integer, i As Integer
CurrentMonth = Month(ADate) - PreviousMonth
TheYear = Year(ADate)
If CurrentMonth <= 0 Then
CurrentMonth = 12 + CurrentMonth
TheYear = TheYear - 1
End If
TheMonth = CurrentMonth
Select Case CurrentMonth
Case 1, 3, 5, 7, 8, 10, 12
LastDayOfMonth = 31
Case 4, 6, 9, 11
LastDayOfMonth = 30
Case 2
LastDayOfMonth = 28
End Select
End Function
Public Function WeekDayName(ByVal WeekDayNum As Integer) As String
Select Case WeekDayNum
Case 1
WeekDayName = “Sunday”
Case 2
WeekDayName = “Monday”
Case 3
WeekDayName = “Tuesday”
Case 4
WeekDayName = “Wednesday”
Case 5
WeekDayName = “Thursday”
Case 6
WeekDayName = “Friday”
Case 7
WeekDayName = “Saturday”
Case Else
MsgBox “This function returns the name of the weekday that was passed in.” & _
“Valid parameter values are 1-7 corresponding to weekdays Sunday through Saturday.”
End Select
End Function
Download the code.