PAPutzback,
In addition to the other comments, I would recommend:
Private Shared Function LastDayOfMonth(ByVal theDate As DateTime) As
DateTime
Dim day As Integer = DateTime.DaysInMonth(theDate.Year,
theDate.Month)
Return New DateTime(theDate.Year, theDate.Month, day)
End Function
Public Shared Sub Main()
Debug.WriteLine(LastDayOfMonth(DateTime.Now))
End Sub
Of course if you want to inline the day variable you could:
Return New DateTime(theDate.Year, theDate.Month, _
DateTime.DaysInMonth(theDate.Year, theDate.Month))
The *major* reason to use a function as above or at least use DateTime.Now
indirectly by assigning it to a variable is that DateTime.Now may change
during the equation, you could get very sporadic results at midnight on the
last day of the month, as DateTime.Now may change over from "this month" to
"next month" midway thru yours or Ken's algorithm. By assigning DateTime.Now
to a variable (or a parameter as above) you avoid any potential problems
with "now" changing.
Hope this helps
Jay
"PAPutzback" <ph**************@insightbb.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
| txtToDate.Text = (Now.Date.AddDays(-(Now.Day)).AddMonths(1))
|