tentavarious
asked on
finding first day and last day of current month vb.net
What is the easiest way to find the first and last day of the current month?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Anyway you can get me the working days in a month, basically subtract all sundays and saturdays
Tertioptus,
You will need to loop through all days and checking if the day is a weekend or not
You will need to loop through all days and checking if the day is a weekend or not
ohhh, okay, thanks
ASKER
Could you give me a small example?
tentavarious,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtmTest As Date = cDateUtil.GetBeginOfCurren tMonth(Dat e.Today)
Dim intWorkableDays As Integer
Do While dtmTest <= cDateUtil.GetEndOfCurrentM onth(Date. Today)
If dtmTest.DayOfWeek <> DayOfWeek.Saturday AndAlso dtmTest.DayOfWeek <> DayOfWeek.Sunday Then
intWorkableDays += 1
End If
dtmTest = dtmTest.AddDays(1)
Loop
MessageBox.Show("there are " + intWorkableDays.ToString + " workable days")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtmTest As Date = cDateUtil.GetBeginOfCurren
Dim intWorkableDays As Integer
Do While dtmTest <= cDateUtil.GetEndOfCurrentM
If dtmTest.DayOfWeek <> DayOfWeek.Saturday AndAlso dtmTest.DayOfWeek <> DayOfWeek.Sunday Then
intWorkableDays += 1
End If
dtmTest = dtmTest.AddDays(1)
Loop
MessageBox.Show("there are " + intWorkableDays.ToString + " workable days")
End Sub
why not just use this: it works in T-SQL and can be slightly altered to for VB using the NOW().
select DATEADD(mm,DATEDIFF(mm,0,G ETDATE()), 0)
select DATEADD(mm,DATEDIFF(mm,0,G
OR: =DateAdd("d",1-DatePart("d ",Today()) ,Today())
Dim d As System.DateTime = Now
MsgBox(d.AddDays(d.DaysInM