Results 1 to 6 of 6

Thread: if statements to test for third Wed of the month & third Thurs. of the month

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    if statements to test for third Wed of the month & third Thurs. of the month

    hello,
    what would be the VB6 code for an if statement that would check for if it's the third wednesday of the month and execute some code based on that. Also would would be the similar code for if it's the third thursday of the month?
    thanks in advance,
    david

  2. #2
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: if statements to test for third Wed of the month & third Thurs. of the month

    The third wednesday will be the wednesday between the 15th and 21st (inclusive). the code is similar for the third thursday with the numbers being the 16th to the 22nd

    so the vb code would look something like

    vbcode Code:
    1. If ((Day = wednesday) + (daynumber >= 15) + (daynumber <= 21)) Then
    2. 'code here
    3. end if

    I'm not sure how you are storing the day of the week and the day number but there is the basic logic for it.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: if statements to test for third Wed of the month & third Thurs. of the month

    Here is code to get the 3rd Wednesday. It is based on some code by member CVMichael.

    vb Code:
    1. Private Sub Form_Load()
    2.    
    3.     MsgBox ThirdWednesday(2007, 3) ' Year and month
    4.    
    5. End Sub
    6.  
    7. Private Function ThirdWednesday(ByVal Y As Integer, ByVal M As Integer) As Date
    8.  
    9.     Dim TheDate As Date
    10.    
    11.     TheDate = DateSerial(Y, M, 1)
    12.    
    13.     TheDate = DateAdd("d", -Weekday(TheDate) + 25, TheDate)
    14.    
    15.     ThirdWednesday = TheDate
    16. End Function

  4. #4
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: if statements to test for third Wed of the month & third Thurs. of the month

    Quote Originally Posted by TBeck
    The third wednesday will be the wednesday between the 15th and 21st (inclusive). the code is similar for the third thursday with the numbers being the 16th to the 22nd.
    Regardless of the day of the week, the third occurance of any given day of the week will be between the 15th and 21st.

    vb Code:
    1. If Weekday(Date) = vbWednesday And Day(Date) >= 15 And Day(Date) <= 21 Then
    2.   MsgBox "Today is the third wednesday of the month"
    3. End If

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: if statements to test for third Wed of the month & third Thurs. of the month

    Something else to note, the third occurance of any given day of week could also happen BEFORE the third occurrance of the day before -- IE, the third Thursday could happen before the third Wednesday.
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    Re: if statements to test for third Wed of the month & third Thurs. of the month

    thanks for everyone's input. With your help, I came up with this test code that worked well as I changed the pc's calendar to the third wed, third thurs and some other days.
    Code:
    If Weekday(Date) = vbWednesday And Day(Date) >= 15 And Day(Date) <= 21 Then
        MsgBox "Today is the third Wednesday of the month"
    Else
        If Weekday(Date) = vbThursday And Day(Date) >= 15 And Day(Date) <= 21 Then
            MsgBox "Today is the third Thursday of the month"
        Else
            MsgBox "today is the " & Weekday(Date) & " / " & Day(Date) & " day of " & Month(Date) & " " & Year(Date)
        End If
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width