Terkadang kita butuh untuk menampilkan tanggal pada bulan tertentu, ada kalanya user ingin menampilkan sebuah laporan rutin setiap bulan berjalan tanpa harus memilih range tanggal untuk bulan tersebut.
berikut adalah fungsi untuk mendapatkan tanggal pertama dan terakhir untuk bulan tertentu:
'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
Demikian semoga bermanfaat, selamat mencoba.
source: https://begeeben.wordpress.com/2012/05/03/get-the-firstlast-day-of-the-month-with-vb-net/