VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Determines difference between two dates. Breaks down to Days, Hours, and Minutes.

by David Koopman (11 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 29th November 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Determines difference between two dates. Breaks down to Days, Hours, and Minutes.

Rate Determines difference between two dates. Breaks down to Days, Hours, and Minutes.




'This function is used to check the Time difference between two valid datetimes.
Private Sub Command1_Click()
Dim stTime, endTime, Diff
Dim Deci, remDec, remMin, remHour
Dim strDay, strHour
'Check to see that entered text fields are valid date formats
If IsDate(Text1.Text) And IsDate(Text2.Text) Then
stTime = CDate(Text1.Text)
endTime = CDate(Text2.Text)
'Get the difference in Minutes between the two dates
Diff = DateDiff("n", stTime, endTime)
'If the difference is greater than 60, break down to hours and minutes.
If Diff >= 60 Then
Diff = Diff / 60
If InStr(1, Diff, ".") Then
Deci = Mid(Diff, InStr(1, Diff, "."), Len(Diff))
remDec = Mid(Deci, 2, Len(Deci))
remMin = (CDbl(Left(remDec, 2)) * 60) / 100
'If Hours are > 24 then break down to Days, Hours, and Minutes
If Round(Diff) > 24 Then
strDay = Round(Diff / 24, 2)
strHour = Round(Mid(strDay, InStr(1, strDay, "."), Len(strDay)) * 24)
Text3.Text = Int(strDay) & " days(s) " & strHour & " hour(s) " & Round(remMin) & " minute(s) to process."
Else
Text3.Text = Round(Diff) & " hour(s) " & Round(remMin) & " minute(s) to process."
End If
Else
Text3.Text = Diff & " hour(s) to process."
Exit Sub
End If
Else
Text3.Text = Diff & " minute(s) to process."
End If
Else
MsgBox "One of the entries is not" & vbCrLf & "a valid date!", vbSystemModal + vbCritical, "Invalid Entry"
Exit Sub
End If
End Sub

Private Sub Form_Load()

Text1.Text = "12/20/2001 12:30:00 PM"
Text2.Text = "12/22/2001 2:33:00 PM"

End Sub


Download this snippet    Add to My Saved Code

Determines difference between two dates. Breaks down to Days, Hours, and Minutes. Comments

No comments have been posted about Determines difference between two dates. Breaks down to Days, Hours, and Minutes.. Why not be the first to post a comment about Determines difference between two dates. Breaks down to Days, Hours, and Minutes..

Post your comment

Subject:
Message:
0/1000 characters