Well, i thought i'd share this with you since it still amuses me.. i wrote this a good few years ago when i was in my teenage years (if its any excuse)
Private Sub Command1_Click()
Dim strDif As Date
Dim strHours As Integer
Dim strMinutes As Integer
Dim strMins As Integer
Dim strOldMinutes As Integer
Dim strSeconds As Integer
Dim strOldSeconds As Integer
Dim strTotalSeconds As Integer
Dim strOnline As String
Dim strDate As Date
Dim strOldDate As Date
Dim strDays As Integer
Dim strNew As Date
Dim strOldDays As Integer
Dim strDifDays As Integer
Dim strMonth As String
Dim strOldMonth As String
Dim strMonthDif As String
Dim strTest As Integer
Dim strNum As Integer
Dim strMod As Integer
Dim strTest2 As Integer
Dim strExtraHours As Integer
Dim strXHours As Integer
Dim strOldXHours As Integer
Dim strTotalMinutes As Integer
Dim strTotalMinutes2 As Integer
Dim strXTotal As Integer
Dim strNum2 As Integer
Dim strNum3 As Integer
Dim strSecTot As Integer
Dim strDayz As Integer
Dim strOldDayz As Integer
Dim strTotalDayz As Integer
Dim intTmp As Integer
Dim intTotal2 As Integer
Dim intMonthDif As Integer
Dim strDayz2 As Integer
Dim strXMonth As Integer
Dim strX2Total As Integer
strDate = "25/03/05"
strOldDate = lblDate.Caption
strNew = "13:42:43"
strOld = lblTime.Caption
If strDate = strOldDate Then
strDif = strNew - strOld
strHours = Mid(strDif, 1, 2)
strMinutes = Mid(strDif, 4, 2)
strSeconds = Mid(strDif, 7, 2)
strOnline = "I have been online for " & strHours & " hour(s), " & strMinutes & " minute(s) and " & strSeconds & " second(s)"
sckIRC.SendData "PRIVMSG #test :" & strOnline & vbCrLf
display Time & " [ CT ]: " & strOnline & vbCrLf
ElseIf strDate <> strOldDate Then
strMonth = Mid(strDate, 4, 2)
strOldMonth = Mid(strOldDate, 4, 2)
If strMonth = strOldMonth Then
strDays = Mid(strDate, 1, 2)
strOldDays = Mid(strOldDate, 1, 2)
strDifDays = strDays - strOldDays
strDifDays = strDifDays + 1
strDifDays = strDifDays - 2
strDifDays = strDifDays * 24
strXHours = Mid(strOld, 1, 2)
strXHours = 24 - strXHours
strOldXHours = Mid(strNew, 1, 2)
strTest = strXHours + strOldXHours + strDifDays
strTest2 = strXHours + strOldXHours + strDifDays
strNum = 0
Do While strTest > 0
strTest = strTest - 24
If strTest > 0 Then
strNum = strNum + 1
Else
'nothing
End If
Loop
strExtraHours = strNum * 24
strExtraHours = strTest2 - strExtraHours
strMinutes = Mid(strNew, 4, 2)
strOldMinutes = Mid(strOld, 4, 2)
strTotalMinutes = strMinutes + strOldMinutes
strTotalMinutes2 = strMinutes + strOldMinutes
If strTotalMinutes > 59 Then
strNum2 = 1
strXTotal = strTotalMinutes - 60
Else
strNum2 = 0
strXTotal = strTotalMinutes
End If
strExtraHours = strExtraHours + strNum2
strSeconds = Mid(strNew, 7, 2)
strOldSeconds = Mid(strOld, 7, 2)
strTotalSeconds = strSeconds + strOldSeconds
If strTotalSeconds > 59 Then
strNum3 = 1
strSecTot = strTotalSeconds - 60
Else
strNum3 = 0
strSecTot = strTotalSeconds
End If
strXTotal = strXTotal + strNum3
If strNum > 1 Then
strOnline = strNum & " days, " & strExtraHours & " hours, " & strXTotal & " minutes and " & strSecTot & " seconds"
sckIRC.SendData "PRIVMSG #test :" & strOnline & vbCrLf
display Time & " [ CT ]: " & strOnline & vbCrLf
Else
strOnline = strNum & " day, " & strExtraHours & " hours, " & strXTotal & " minutes and " & strSecTot & " seconds"
sckIRC.SendData "PRIVMSG #test :" & strOnline & vbCrLf
display Time & " [ CT ]: " & strOnline & vbCrLf
End If
'lblTest.Caption =
ElseIf strMonth <> strOldMonth Then
strDayz = Mid(strDate, 1, 2)
strOldDayz = Mid(strOldDate, 1, 2)
If (strOldMonth = 2) Then
strDays = 28
ElseIf (strOldMonth = 4) Or (strOldMonth = 6) Or (strOldMonth = 9) Or (strOldMonth = 11) Then
strDays = 30
ElseIf (strOldMonth = 1) Or (strOldMonth = 3) Or (strOldMonth = 5) Or (strOldMonth = 7) Or (strOldMonth = 8) Or (strOldMonth = 10) Or (strOldMonth = 12) Then
strDays = 31
End If
If ((strMonth - strOldMonth) = 1) Then
strOldDayz = strDays - strOldDayz
strTotalDayz = strOldDayz + strDayz
Else
intTmp = strMonth
intTmp = intTmp - 1
intTotal2 = 0
Do While (intTmp < strMonth) And (intTmp > strOldMonth)
If (intTmp = 2) Then
strDayz2 = 28
ElseIf (intTmp = 4) Or (intTmp = 6) Or (intTmp = 9) Or (intTmp = 11) Then
strDayz2 = 30
ElseIf (intTmp = 1) Or (intTmp = 3) Or (intTmp = 5) Or (intTmp = 7) Or (intTmp = 8) Or (intTmp = 10) Or (intTmp = 12) Then
strDayz2 = 31
End If
intTotal2 = intTotal2 + strDayz2
intTmp = intTmp - 1
Loop
strXMonth = strDays - strOldDayz
strTotalDayz = strXMonth + intTotal2 + strDayz
End If
Dim num4 As Integer
Dim intTot As Integer
strMinutes = Mid(strNew, 4, 2)
strOldMinutes = Mid(strOld, 4, 2)
strXHours = Mid(strNew, 1, 2)
strOldXHours = Mid(strOld, 1, 2)
strOldXHours = 24 - strOldXHours
strExtraHours = strOldXHours + strXHours
strTotalMinutes = strMinutes + strOldMinutes
If strTotalMinutes > 59 Then
strNum2 = 1
strXTotal = strTotalMinutes - 60
Else
strNum2 = 0
strXTotal = strTotalMinutes
End If
strExtraHours = strExtraHours + strNum2
strSeconds = Mid(strNew, 7, 2)
strOldSeconds = Mid(strOld, 7, 2)
strTotalSeconds = strSeconds + strOldSeconds
If strTotalSeconds > 59 Then
strNum3 = 1
strSecTot = strTotalSeconds - 60
Else
strNum3 = 0
strSecTot = strTotalSeconds
End If
strXTotal = strXTotal + strNum3
If strTotalDayz > 1 Then
strOnline = strTotalDayz & " days, " & strExtraHours & " hours, " & strXTotal & " minutes and " & strSecTot & " seconds"
sckIRC.SendData "PRIVMSG #test :" & strOnline & vbCrLf
display Time & " [ CT ]: " & strOnline & vbCrLf
Else
sckIRC.SendData "PRIVMSG #test :" & strOnline & vbCrLf
display Time & " [ CT ]: " & strOnline & vbCrLf
strOnline = strTotalDayz & " day, " & strExtraHours & " hours, " & strXTotal & " minutes and " & strSecTot & " seconds"
End If
End If
End If
End Sub
It basically works out the duration between 2 times.. god knows why i did it like that, i'm sure it can be done with 1/2 lines or something, but at the time, well i was naive. It was for an irc bot (you don't want to see the rest of the code!), so i thought i'd post it here, since it wasn't exactly going to kill anyone. Nice huh?