สำนักวิทยบริการและเทคโนโลยีสารสนเทศ (สวส.)

Office of Academic Resources and Information Technology


Office of Academic Resources and Information Technology

ฟังก์ชั่นหาวันแรกและวันสุดท้ายของเดือน (Get first and last day of month)

  1. 'VB.NET  
  2. 'หาวันแรกของเดือน จากวันปัจจุบัน  
  3. Function GetFirstDayOfMonth(ByVal CurrentDate As DateTime) As DateTime  
  4.    Return (New DateTime(CurrentDate.Year, CurrentDate.Month, 1))  
  5. End Function  
 
  1. 'หาวันแรกของเดือน ที่เป็นวันทำงาน (จันทร์-ศุกร์) จากวันปัจจุบัน  
  2. Function GetFirstWorkingDayOfMonth(ByVal CurrentDate As DateTime) As DateTime  
  3.    With New DateTime(CurrentDate.Year, CurrentDate.Month, 1)  
  4.       If .DayOfWeek = DayOfWeek.Saturday Then  
  5.          Return .AddDays(2)  
  6.       ElseIf .DayOfWeek = DayOfWeek.Sunday Then  
  7.          Return .AddDays(1)  
  8.       Else  
  9.          Return .AddDays(0)  
  10.       End If  
  11.    End With  
  12. End Function  
 
  1. 'หาวันสุดท้ายของเดือน จากวันปัจจุบัน  
  2. Function GetLastDayOfMonth(ByVal CurrentDate As DateTime) As DateTime  
  3.    With CurrentDate  
  4.       Return (New DateTime(.Year, .Month, Date.DaysInMonth(.Year, .Month)))  
  5.    End With  
  6. End Function