|
-
Jan 10th, 2007, 07:10 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Total Time
Hi,
If i have 2 values in a database, how would i work out what the time is between the two times??
Example:
Value 1: 12:01:00 PM
Value 2: 12:02:24 PM
Then i want it to return 00:01:24
Any idea??
Thanks,
Ross
-
Jan 10th, 2007, 07:31 AM
#2
Re: Total Time
one way
VB Code:
x = DateDiff("s", value1, Value2)
x = x \ 60 & ":" & x Mod 60
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 10th, 2007, 10:50 AM
#3
Re: Total Time
Moved to Database forum
Which database system are you using?
Do you want this done in an SQL statement, or in your program, or...?
Another possible method (may not work, depending on the kind of values you will have) is simply: Value2 - Value1
-
Jan 11th, 2007, 08:45 AM
#4
Thread Starter
Addicted Member
Re: Total Time
 Originally Posted by westconn1
one way
VB Code:
x = DateDiff("s", value1, Value2)
x = x \ 60 & ":" & x Mod 60
I tried this method and it came out like this:
Value 1 = 1:34:38 PM
Value 2 = 1:37:43 PM
x = 3:5
3:5 isn't really a time any ideas??
-
Jan 11th, 2007, 09:12 AM
#5
Re: Total Time
Code:
format(cdate(<value2>)-cdate(<value1>),"hh:nn:ss")
or the date diff posted above...
Value 1 and value 2 are text in my example (hence the cdate function).
Value 2 MUST be greater than value 1. Although you could wrap that in an abs function.
All dates are stored as long (I think) past a certain point in the past (until we go past 2029 then things may be interesting )
So the above converts the text to dates (longs) and minuses one from the other. Whatever is left is formatted to a date.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jan 11th, 2007, 09:15 AM
#6
Thread Starter
Addicted Member
Re: Total Time
format(cdate(<value2>)-cdate(<value1>),"hh:nn:ss")
is that meant to be mm??
-
Jan 11th, 2007, 12:24 PM
#7
Re: Total Time
No, as "m" is used for Month.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|