VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Last day of the month

by Karabunga (2 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Returns the last day of a specified month. Takes into account leap years.

Inputs
Month (optional), Year (optional)
Code Returns
Last day of the month

Rate Last day of the month

Function LastDay(Optional MyMonth As Integer, Optional MyYear As Integer) As Integer
  ' Returns the last day of the month. Takes into account leap years
  ' Usage: LastDay(Month, Year)
  ' Example: LastDay(12,2000) or LastDay(12) or Lastday
  
  If MyMonth = 0 Then MyMonth = Month(Date)
  Select Case MyMonth
    Case 1, 3, 5, 7, 8, 10, 12
      LastDay = 31
      
    Case 4, 6, 9, 11
      LastDay = 30
      
    Case 2
      If MyYear = 0 Then MyYear = Year(Date)
      
      If IsDate(MyYear & "-" & MyMonth & "-" & "29") Then LastDay = 29 Else LastDay = 28
      
    Case Else
      LastDay = 0
  
  End Select
  
End Function

Download this snippet    Add to My Saved Code

Last day of the month Comments

No comments have been posted about Last day of the month. Why not be the first to post a comment about Last day of the month.

Post your comment

Subject:
Message:
0/1000 characters