How to get first and last day of given date using vb.net
How to get first and last day of given date using vb.net
How to get first and last day of given date using vb.net
Abstract
In page load event just call the GetFirstDayInMonth and GetLastDayInMonth it will return first and last day of the give date.
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
MsgBox(GetFirstDayInMonth("#2010-06-19#"), MsgBoxStyle.OkCancel, "First Day of The Month")
MsgBox(GetLastDayInMonth("#2010-06-20#"), MsgBoxStyle.OkCancel, "Last Day of The Month")
End If
End Sub
Function GetLastDayInMonth(ByVal dtDate As Date) As Date
Return DateAdd(DateInterval.Day, (Day(DateAdd(DateInterval.Month, 1, dtDate))) * -1, DateAdd(DateInterval.Month, 1, dtDate))
End Function
Function GetFirstDayInMonth(ByVal dtDate As Date) As Date
Return Now.AddDays((Now.Day - 1) * -1)
End Function
End Class
