• RyanDev.com

  • Date and Time Useful Functions for VB 6.0

16th February 2008

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.

This entry was posted on Saturday, February 16th, 2008 at 8:43 pm and is filed under General Software Development, Microsoft Office. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 5 responses to “Date and Time Useful Functions for VB 6.0”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On November 10th, 2008, Nysa said:

    Good for people to know.

  2. 2 On December 10th, 2008, Olechka-persik said:

    Thanks for post. Nice to see such good ideas.

  3. 3 On November 5th, 2009, Abbett said:

    Having such respected industry experts lend their support and professional expertise is great.

  4. 4 On October 19th, 2010, lively said:

    Thanks for good stuff

  5. 5 On October 23rd, 2010, bad mash said:

    I just signed up to your blogs rss feed. Will you post more on this subject?

Leave a Reply

  • Links

  • Calendar

  • February 2012
    S M T W T F S
    « Jan    
     1234
    567891011
    12131415161718
    19202122232425
    26272829