• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

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.

Eg:
Todays date : 04/25/2006

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

Any ideas ?

Thanks,
0
karthikram
Asked:
karthikram
2 Solutions
 
É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


Cheers!
0
 
wtconwayCommented:
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now