Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Calculation

Status
Not open for further replies.

M626

Programmer
Joined
Mar 13, 2002
Messages
299
I am trying to read in a document and calcuate time. What it should do is check if the time is > than #.53 and < than #.07 in time format and if it is, round what ever # is to #.00 but if not check the difference between the time ie: 7:05am and 3:10pm would be 8:15 minutes. Here is some code I been trying to do this with.

If Seven_To >= "57" And Seven_To <= "03" And Seven_After >= "53" And Seven_After <= "07" Then

TimeTotal = DateDiff("h", CDate(TimeStart & " " & DateIN), CDate(TimeEnd & " " & DateOUT))
tStreamOut.Write sBuffer & " " & (TimeTotal) & vbCrLf
TotalHrsWrk = Val(TimeTotal) + Val(TotalHrsWrk)
Else

TimeTotal = DateDiff("n", CDate(TimeStart & " " & DateIN), CDate(TimeEnd & " " & DateOUT))
tStreamOut.Write sBuffer & " " & Format((TimeTotal / 60), "##.00") & vbCrLf
TimeTotal = Format((TimeTotal / 60), "##.00")
TotalHrsWrk = Val(TimeTotal) + Val(TotalHrsWrk)

End If
 



Hi,

Date/Time is a NUMBER, like NOW is 39251.38565 in north Texas.
Code:
TimeTotal = DateDiff("h", TimeStart + DateIN, TimeEnd + DateOUT)

Skip,

[glasses] [red][/red]
[tongue]
 


What is Seven_To and Seven_After decalered as? I would guess As String, but I could be wrong.

Your logic will never work this way. What would Seven_To had to be for both of these statements to be True:
If Seven_To >= "57" And Seven_To <= "03"
The If statement will ALWAYS be FALSE.

Same goes for:
Seven_After >= "53" And Seven_After <= "07"

You can have one OR another, but never both.

And if you combine both statement, your code will NEVER past this logic.


Have fun.

---- Andy
 




BTW,

You can SIMPLY do arithmetic on your Time Values to get the difference...
Code:
t1 = #7:05:00 AM#
t2 = #3:15:00 PM#
MsgBox "the difference is " & Format(t2 - t1, "hh:nn")
the actual VALUE of the difference is 0.340277777777777, a NUMBER.

Skip,

[glasses] [red][/red]
[tongue]
 

Not if you declare t1 and t2 as Date:
Code:
Private Sub Command1_Click()
Dim t1 As Date
Dim t2 As Date

t1 = "7:05:00 AM"
t2 = "3:15:00 PM"

msgBox "the difference is " & Format(t2 - t1, "hh:nn")
the difference is 08:10



Have fun.

---- Andy
 



Code:
Dim t1 As Date
Dim t2 As Date

t1 = "7:05:00 AM"
t2 = "3:15:00 PM"

MsgBox "the difference is " & t2 - t1
the difference is 0.340277777777777 ;-)

Skip,

[glasses] [red][/red]
[tongue]
 
But what if it starts from one day to the next.

t1 = "11:01 PM" '6/12/07
t2 = "7:00 AM" '6/13/07


 



TIME is part of DATE...
Code:
t1 = Date + #11:01 PM#  '6/12/07
t2 = Date + 1 + #7:00 AM#   '6/13/07
msgbox t2-t1
# is the Date/Time converter.

Skip,

[glasses] [red][/red]
[tongue]
 
How can i skip lines that may be blank in the file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top