Thursday, February 19, 2009

MonthFirst,MonthEnd for VB.Net



Version Compatibility : VB.Net 2005

More information : MonthFirst and MonthEnd for VB.net. it same vb6. use function name DateSerial and DateTime.Now().

Source Code :

Public Function MonthFirst(ByVal pDate As DateTime) As DateTime
Try
Return DateSerial(Year(pDate), Month(pDate), 1)
Catch ex As Exception
Return DateSerial(Year(DateTime.Now()), Month(DateTime.Now()), 1)
End Try
End Function

Public Function MonthEnd(ByVal pDate As DateTime) As DateTime
Try
Return DateSerial(Year(pDate), Month(pDate) + 1, 1).AddDays(-1)
Catch ex As Exception
Return DateSerial(Year(DateTime.Now()), Month(DateTime.Now()) + 1, 1).AddDays(-1)
End Try
End Function

For Example Use :

Call MonthFirst("15/01/2009") ' Return "01/01/2009"
Call MonthEnd("15/01/2009") ' Return "31/01/2009"

*** if you Call MonthEnd Febuary result is 28 or 29.

0 Comment:

 

programmingassist. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com