Re: How to calculate the time difference
Quote:
Originally Posted by
vbzero
OK guys! - I just got it. Don't need that code.
When I calculate 24 - StartTimeValue + EndTimeValue
then it returns the difference.
Sometimes it's as easy as you would think.
thx, sub-zero
I'm not sure that your previous code will work quit well
but try this :
============
'Here you go :
Dim ADate, A1Date, BDay, B1Day, CMonth, C1Month, DYear, D1Year
ADate = Date
'If you want to calculate time diff in the same day, just delete the "+ 1"
A1Date = ADate + 1
BDay = Day(ADate)
B1Day = Day(A1Date)
CMonth = Month(ADate)
C1Month = Month(A1Date)
DYear = Year(ADate)
D1Year = Year(A1Date)
Dim MystrtTime, MyendTime, strtDATEnTIME, endDATEnTIME, RetVal, GetMinDiff, GetHours, GetMinutes, FinalDiff
MystrtTime = Format("06:10:00 PM", "hh:mm:ss AM/PM")
MyendTime = Format("06:50:00 AM", "hh:mm:ss AM/PM")
endDATEnTIME = Format(B1Day & "-" & C1Month & "-" & D1Year & " " & MyendTime, "dd-mm-yyyy hh:mm:ss")
strtDATEnTIME = Format(BDay & "-" & CMonth & "-" & DYear & " " & MystrtTime, "dd-mm-yyyy hh:mm:ss")
' Get Hours
GetHours = Int(((DateDiff("s", strtDATEnTIME, endDATEnTIME) / 60) / 60))
'Get Minutes
GetMinDiff = Int(((((DateDiff("s", strtDATEnTIME, endDATEnTIME) / 60) / 60)) - Int(((DateDiff("s", strtDATEnTIME, endDATEnTIME) / 60) / 60))) * 60)
If GetMinDiff >= 60 Then
GetMinutes = GetMinDiff - 60
GetHours = GetHours + 1
Else
GetMinutes = GetMinDiff
End If
FinalDiff = GetHours & ":" & GetMinutes
RetVal = Format(FinalDiff, "hh:mm:ss")
MsgBox RetVal
' Done
BR,
Mous
Re: How to calculate the time difference
Welcome to the forums Mous :)
I don't think he still needs help with this (14 years later). See the main page of this Forum, there you'll find many active threads.
Re: How to calculate the time difference
AND, you have some issues with the way you are declaring variables.....:-)
Re: How to calculate the time difference
Thanks for your replies :)
I know its too old , but almost every one use your forum as a reference so I wanted to complete the thread.
dear sam ,
would you please fix my code issues , so I could learn from you , and other Google searchers will find a good complete article :)
Thank you again.
Re: How to calculate the time difference
Well, I won't go through all that code, but I would suggest you read this about declaring variables:
(In Visual Basic 6.0, you can declare variables of different types in the same statement, but you must specify the data type of each variable or it defaults to Variant.)
http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx
Re: How to calculate the time difference
We have a policy not to resurrect threads that are older than one year. Thread closed.