'VB.NET 'หาวันแรกของเดือน จากวันปัจจุบัน Function GetFirstDayOfMonth(ByVal CurrentDate As DateTime) As DateTime Return (New DateTime(CurrentDate.Year, CurrentDate.Month, 1)) End Function
'หาวันแรกของเดือน ที่เป็นวันทำงาน (จันทร์-ศุกร์) จากวันปัจจุบัน
Function GetFirstWorkingDayOfMonth(ByVal CurrentDate As DateTime) As DateTime
With New DateTime(CurrentDate.Year, CurrentDate.Month, 1)
If .DayOfWeek = DayOfWeek.Saturday Then
Return .AddDays(2)
ElseIf .DayOfWeek = DayOfWeek.Sunday Then
Return .AddDays(1)
Else
Return .AddDays(0)
End If
End With
End Function'หาวันสุดท้ายของเดือน จากวันปัจจุบัน
Function GetLastDayOfMonth(ByVal CurrentDate As DateTime) As DateTime
With CurrentDate
Return (New DateTime(.Year, .Month, Date.DaysInMonth(.Year, .Month)))
End With
End Function
แหล่งข้อมูล :first day of month - eggheadcafe
First and Last Day Of Month - vbforums