Get first day of the month and last day of the month in VB.NET

Private Function GetFirstDayOfMonth(ByVal dtDate As DateTime) As DateTime
        Dim dtFrom As DateTime = dtDate
        dtFrom = dtFrom.AddDays(-(dtFrom.Day - 1))
        Return dtFrom
    End Function

    Private Function GetLastDayOfMonth(ByVal dtDate As DateTime) As DateTime
        Dim dtTo As New DateTime(dtDate.Year, dtDate.Month, 1)
        dtTo = dtTo.AddMonths(1)
        dtTo = dtTo.AddDays(-(dtTo.Day))
        Return dtTo
    End Function

'if you put code like:
GetFirstDayOfMonth("2010-05-05") ' It will return = 2010-05-01
GetLastDayOfMonth("2010-05-05") ' It will return = 2010-05-31

Reff: http://redsouljaz.com/2010/06/03/get-first-day-of-the-month-and-last-day-of-the-month-in-vb-net/

Advertisements
By simplemsexchange Posted in VB.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s