[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need to find first monday..friday of month

Posted on 2006-11-01
2
Medium Priority
?
447 Views
Last Modified: 2010-04-23
Hi

I need to find a specific day in a month based on an occurance of that day.

ie I need to find first monday of month, second tuesday of month, 4th friday of month .. etc Basically any day in a cycle of a month over a period of a year.

Thanks
Chuck
0
Comment
Question by:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 17854434
How about something like?

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Find the second Monday in October of 2006...
        Dim dt As DateTime = GetSpecificDate(2, DayOfWeek.Monday, 10, 2006)
        Debug.WriteLine(dt.ToString)
    End Sub

    Private Function GetSpecificDate(ByVal occurence As Integer, ByVal dayOfWeek As DayOfWeek, ByVal month As Integer, ByVal year As Integer) As DateTime
        Dim returnDt As DateTime = Nothing

        Try
            Dim counter As Integer = 0
            Dim startDt As DateTime = New DateTime(year, month, 1, 0, 0, 0)
            If occurence >= 1 Then
                While True
                    While startDt.DayOfWeek <> dayOfWeek
                        startDt = startDt.AddDays(1)
                    End While
                    counter = counter + 1

                    If counter = occurence Then
                        If startDt.Month = month Then
                            returnDt = startDt
                        End If

                        Exit While
                    Else
                        startDt = startDt.AddDays(1)

                        If startDt.Month <> month Then
                            Exit While
                        End If
                    End If
                End While
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error Finding Date", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

        Return returnDt
    End Function
0
 

Author Comment

by:Charles Baldo
ID: 17854568
Looks workable

Thanks a ton Idle Mind
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question