Calendars

Is there any function or something in VB 5 that can help with what dates fall on what days of a month. For example: If I have the month of January on a form. Is there a function that knows what day the first would fall on, how many days there are and what day february starts given what year it was. Thanks in advance


Josh


Comments

  • I know of no function that will do this, but the code for something like this is fairly simple.


    Add the number of days proceding this one in a year, modified by a number indicating what day of the year Jan 1st fell on (and a number for a leap year) and Mod 7. The final value tells you the day.

    I wrote this code for practice once, and can honestly say it is simple and short. I'll duplicate it in VB and re-post when I finish it.


  • This function isn't quite complete, but you should be able to finish it with no problem. It works, but I only coded enough for 1999 and Sunday through Wednesday.


    Function DayOfWeek (ByVal Today As Integer, ByVal ThisMonth As Integer, ByVal ThisYear As Integer) As String

    'ByVals aren't really necessary I suppose, but I tend to use them anyway

    'It's better (for me) than ensuring I use a string variable instead of a variant


    'Find what day of the year it is

    If ThisMonth > 1 Then Today = Today + 31

    If ThisMonth > 2 And (ThisYear Mod 4 = 0) Then

    Today = Today + 29

    ElseIf ThisMonth > 2 And (ThisYear Mod 4 > 0) Then

    Today = Today + 28

    End If

    If ThisMonth > 3 Then Today = Today + 31

    If ThisMonth > 4 Then Today = Today + 30

    If ThisMonth > 5 Then Today = Today + 31

    If ThisMonth > 6 Then Today = Today + 30

    If ThisMonth > 7 Then Today = Today + 31

    If ThisMonth > 8 Then Today = Today + 31

    If ThisMonth > 9 Then Today = Today + 30

    If ThisMonth > 10 Then Today = Today + 31

    If ThisMonth > 11 Then Today = Today + 30

    'I think there's a function which does the above, but I don't know what it is

    'What day was Jan 1st?

    'You'll have to check and add code.

    'If Jan 1st was Sunday then add 0

    'Monday, add 1, etc.

    'Easily written to adjust for year, i.e.

    If ThisYear = 1999 Then Today = Today + 5

    'because Jan 1, 1999 was a Friday

    WhatDay = Today Mod 7

    Select Case WhatDay

    Case 1

    DayOfWeek = "Sunday"

    Case 2

    DayOfWeek = "Monday"

    Case 3

    DayOfWeek = "TuesDay"

    Case 4

    DayOfWeek = "Wednesday"

    'So on, so forth, get the idea?

    End Select


    End Function


    If finished, this code will take any date and tell you the day of the year it's on, provided you have coded in that year.


  • : Is there any function or something in VB 5 that can help with what dates fall on what days of a month. For example: If I have the month of January on a form. Is there a function that knows what day the first would fall on, how many days there are and what day february starts given what year it was. Thanks in advance


    : Josh


    If you still need source code let me know.





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories