Function leap(ByVal ym As String)
Dim yy, mm, dd, ydate As String
yy = Left(ym, 4)
mm = Right(ym, 2)
Select Case mm
Case "01", "03", "05", "07", "08", "10", "12"
dd = "31"
Case "04", "06", "09", "11"
dd = "30"
Case Else
If yy Mod 4 = 0 Or yy Mod 400 = 0 Then
dd = "29"
Else
dd = "28"
End If
End Select
ydate = yy + "-" + mm + "-" + dd
Return ydate
End Function