Finding Last day of Month

How do i find the last day of a month. I need to find the first and last date of a previous month.

Todays date : 04/25/2006

Result : 03/01/2006 - 03/31/2006

Any ideas ?

Who is Participating?
This will do it:

    Public Function LastDayOfMonth(ByVal p_Month As Integer) As DateTime
        Dim dtm As New DateTime(Now.Year, p_Month + 1, 1)
        Return dtm.AddDays(-1)
    End Function

Dim lastDay as DateTime = LastDayOfMonth(3) 'last day of march
Éric MoreauSenior .Net ConsultantCommented:
Hi karthikram,

I use these methods:
    Public Shared Function GetBeginOfCurrentMonth(ByVal pDate As Date) As Date
        Return Date.Parse(pDate.Year.ToString & "/" & pDate.Month.ToString & "/01")
    End Function
    Public Shared Function GetBeginOfPreviousMonth(ByVal pDate As Date) As Date
        Dim dtmEOPM As Date = GetEndOfPreviousMonth(pDate)
        Return Date.Parse(dtmEOPM.Year.ToString & "/" & dtmEOPM.Month.ToString & "/01")
    End Function
    Public Shared Function GetEndOfPreviousMonth(ByVal pDate As Date) As Date
        Return GetBeginOfCurrentMonth(pDate).AddDays(-1)
    End Function

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.