|
-
August 1st, 2010, 12:52 AM
#1
Get date of Sunday within a month
Hi,
Can anyone advice how can I get the date of first Sunday in a month?
For example in January, the first date of Sunday is 7. What code is needed to retrieve first Sunday date in a month?
-
August 2nd, 2010, 02:02 AM
#2
Re: Get date of Sunday within a month
Something like this :
Code:
Public Class Form1
Public Function GetFirstSunday(ByVal intMonth As Integer, ByVal intYear As Integer) As DateTime
' Create a start date for the 1st day of the month
Dim dtStartDate As DateTime = New DateTime(intYear, intMonth, 1)
' Keep looping, adding dayss to the start date until sunday is reached
While dtStartDate.DayOfWeek <> DayOfWeek.Sunday
dtStartDate = dtStartDate.AddDays(1)
End While
' Then return date of first sunday of month
Return dtStartDate
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(GetFirstSunday(8, 2010)) 'Returns First Sunday In August, 2010
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|