|
-
Dec 3rd, 2006, 01:05 AM
#1
Thread Starter
Fanatic Member
time adder
get the function to add time
WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST 
-
Dec 3rd, 2006, 01:07 AM
#2
-
Dec 3rd, 2006, 01:14 AM
#3
Thread Starter
Fanatic Member
Re: time adder
we have to ADD hrs and minutes.
for an example ...
01:30 and 02:30 should give us 4 hrs as answer.
WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST 
-
Dec 3rd, 2006, 01:17 AM
#4
-
Dec 3rd, 2006, 01:39 AM
#5
Thread Starter
Fanatic Member
Re: time adder
its not working..
i have tried it
i have given as
dateadd("h","01:30","2:30") it gives me error as typemismatch
and for
dateadd("h","01.30","2:30") it gives me result as "02:30"
WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST 
-
Dec 3rd, 2006, 01:44 AM
#6
Re: time adder
That's the same code, how can it give you both a type mismatch error and a result?
You need to pass it date variables, not strings.
-
Dec 3rd, 2006, 03:59 AM
#7
Re: time adder
It is not the same code.
In the first sample, the second argument is a time value. In the second sample it is a decimal value (which is correct).
Even though the second argument is defined as a double, you cannot add decimal portions (ie 1.5 hours). VB rounds the value to the nearest integer.
So to add 1.5 hours, use minutes instead
DateAdd("n", 90, "2:30")
Last edited by brucevde; Dec 3rd, 2006 at 04:03 AM.
-
Dec 3rd, 2006, 05:21 AM
#8
Re: time adder
try datediff instead
VB Code:
x = DateDiff("h", "01:30", "2:30") ' returns 1
but if you time is in hours minutes you will have to get the difference in minutse and then calculte it to hours and minutes
VB Code:
Dim t As Date
x = DateDiff("n", "01:30", "2:35") ' returns 65
t = 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
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
|