RSS

Get the first/last day of the month with VB.NET

03 May

Getting the first and last day of the month is pretty simple with .NET DateTime object constructor. The functions below are rewritten from Getting the First and Last day of the month with .NET C# in VB.NET.

'Get the first day of the month
Public Function FirstDayOfMonth(ByVal sourceDate As DateTime) As DateTime    
    Return New DateTime(sourceDate.Year, sourceDate.Month, 1)
End Function

'Get the last day of the month
Public Function LastDayOfMonth(ByVal sourceDate As DateTime) As DateTime
    Dim lastDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
    Return lastDay.AddMonths(1).AddDays(-1)
End Function
Advertisements
 
Leave a comment

Posted by on May 3, 2012 in .NET, VB

 

Tags:

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

 
%d bloggers like this: