[Windows Forms] [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
'根據日期取得上個月的最後一天
Public Shared Function LastDayOfLastMonth(ByVal sourceDate As DateTime) As DateTime
Dim lastDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
Return lastDay.AddMonths(0).AddDays(-1)
End Function
'根據日期取得下個月的第一天
Public Shared Function FirstDayOfNextMonth(ByVal sourceDate As DateTime) As DateTime
Dim NextDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
Return NextDay.AddMonths(1).AddDays(0)
End Function