StrataFrame Forum

Calculating dates of previous month...

http://forum.strataframe.net/Topic5844.aspx

By StarkMike - 1/15/2007

Here's how I am determining the first and last day of the previous month.



Me.tbdtpStartDate.EditValue = DateSerial(Year(Now()), Month(Now()) - 1, 1)

Me.tbdtpEndDate.EditValue = DateSerial(Year(Now()), Month(Now()), 0)



It seems to me there should be a more elegant way in VB .NET. Does anybody know of one?
By StrataFrame Team - 1/16/2007

You can do it the more .NET way like this:

Dim n As DateTime = DateTime.Now
Me.tbdtpStartDate.EditValue = New DateTime(n.Year, n.Month - 1, 1)
Me.tbdtpEndDate.EditValue = New DateTime(n.Year, n.Month - 1, DateTime.DaysInMonth(n.Year, n.Month - 1))

By StarkMike - 1/16/2007

Thanks Ben. Too bad I couldnt go Now.PreviousMonth

Wink

By StrataFrame Team - 1/16/2007

Yeah, but you could write a helper method that would encapsulate it Wink