Function datetonum(ByVal str1 As String)
Dim length As Integer
Dim noofdays As String
Dim char1 As Char
Dim marker As Integer = 1
Dim month As String = ""
Dim day As String = ""
Dim year As String = ""
Dim leap As Boolean = False
length = Len(str1)
For i As Integer = 1 To length
char1 = Mid(str1, i, 1)
If char1 = "/" Then
marker = marker + 1
Else
If marker = 1 Then
month = month & char1
End If
If marker = 2 Then
day = day & char1
End If
If marker = 3 Then
year = year & char1
End If
End If
Next
If month <= 9 Then
month = "0" & month
End If
If day <= 9 Then
day = "0" & day
End If
year = Mid(year, 1, 4)
noofdays = day + monthtodays(month, year) + yearstodays(year)
Return noofdays
End Function
Function yearstodays(ByVal num1 As Integer)
Dim years As Integer
Dim leap As Boolean = False
Dim days As Integer = 0
Do While years < num1 - 1
If years Mod 4 = 0 And years > 3 Then
If Not years Mod 100 = 0 Then
leap = True
Else
If years Mod 400 = 0 Then
leap = True
End If
End If
End If
If leap Then
days = days + 366
Else
days = days + 365
End If
years = years + 1
Loop
Return days
End Function
Function monthtodays(ByVal num1 As Integer, ByVal year As Integer)
Dim month As Integer
Dim leap As Boolean = False
Dim days As Integer = 0
For month = 0 To num1 - 1
If year Mod 4 = 0 And year > 3 Then
If Not year Mod 100 = 0 Then
leap = True
Else
If year Mod 400 = 0 Then
leap = True
End If
End If
End If
If month = 4 Or month = 6 Or month = 9 Or month = 11 Then
days = days + 30
End If
If month = 2 Then
If leap Then
days = days + 29
Else
days = days + 28
End If
End If
If month = 1 Or month = 3 Or month = 5 Or month = 7 Or month = 8 Or month = 10 Or month = 12 Then
days = days + 31
End If
Next month
Return days
End Function
Function numtodate(ByVal int1 As Integer)
Dim year As String
Dim month As Integer = 1
Dim days As Integer = 1
Dim test As Integer = int1
Dim leap As Boolean = False
Dim returndate As String
year = findyear(int1)
month = findmonth(int1 - datetonum("1/1/" & year))
days = int1 - (datetonum(month & "/1/" & year)) + 1
If month <= 9 Then
month = "0" & month
End If
If days <= 9 Then
days = "0" & days
End If
year = Mid(year, 1, 4)
returndate = month & "/" & days & "/" & year
Return returndate
End Function
Function findyear(ByVal int1 As Integer)
Dim year As Integer = 1
Dim month As Integer = 1
Dim days As Integer = 1
Dim test As Integer = int1
Dim leap As Boolean = False
While (test > 365 And leap = False) Or (test > 366 And leap = True)
If year Mod 4 = 0 And year > 3 Then
If Not year Mod 100 = 0 Then
leap = True
Else
If year Mod 400 = 0 Then
leap = True
End If
End If
End If
If leap = True Then
test = test - 366
Else
test = test - 365
End If
year = year + 1
End While
Return year
End Function
Function findmonth(ByVal int1 As Integer)
Dim year As Integer = 1
Dim month As Integer = 1
Dim days As Integer = 1
Dim test As Integer = int1
Dim leap As Boolean = False
While test > 31
If month = 4 Or month = 6 Or month = 9 Or month = 11 Then
test = test - 30
End If
If month = 2 Then
If leap Then
test = test - 29
Else
test = test - 28
End If
End If
If month = 1 Or month = 3 Or month = 5 Or month = 7 Or month = 8 Or month = 10 Or month = 12 Then
test = test - 31
End If
month = month + 1
End While
Return month
End Function