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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can subtract long time

Status
Not open for further replies.

darkdido

Programmer
Nov 23, 2005
8
SD
Dim Time1 As String
Dim Time2 As String
Dim Hours As Long
Dim Minutes As Long

Time1 = "40644:30:00"
Time2 = "20:15:00"

Hours = CLng(Split(Time1, ":")(0)) + CLng(Split(Time2, ":")(0))
Minutes = CLng(Split(Time1, ":")(1)) + CLng(Split(Time2, ":")(1))

Hours = Hours + CLng(Minutes / 60 - 0.5)
Minutes = Minutes Mod 60

Debug.Print Hours & ":" & Minutes


this is nice but is have problem when i need subtract its not wrok

like 11:00-1:15= 9:-15 its wrong
but i use is
Dim dteTemp As Date
Dim Time1 As String
Dim Time2 As String

Time1 = "11:00"
Time2 = "1:15"

dteTemp = TimeValue(Val(Split(Time1, ":")(0)) - Val(Split(Time2, ":")(0)), Val(Split(Time1, ":")(1)) - Val(Split(Time2, ":")(1)), 0)

Debug.Print = DateDiff("D", CDate(0), dteTemp) * 24 + Hour(dteTemp) & ":" & Minute(dteTemp)
but its not work with long time (40644:30:00-1:15)
 
As I said to you in thread222-1163662, start with FAQ222-2244 to see how this forum works - you have asked several questions, got loads of answers and haven't yet said whether any of them worked - or even acknowledged them. Check especially paragraphs 11, 12, 14 , 15 and 16

For this question, you've omitted the Mod operator!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
i am realy sorry but i forget

ineed help me in this


Dim dteTemp As Date
Dim Time1 As String
Dim Time2 As String

Time1 = "11:00"
Time2 = "1:15"

dteTemp = TimeValue(Val(Split(Time1, ":")(0)) - Val(Split(Time2, ":")(0)), Val(Split(Time1, ":")(1)) - Val(Split(Time2, ":")(1)), 0)

Debug.Print = DateDiff("D", CDate(0), dteTemp) * 24 + Hour(dteTemp) & ":" & Minute(dteTemp)
but its not work with long time (40644:30:00-1:15)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top