Results 1 to 8 of 8

Thread: time adder

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    time adder

    get the function to add time
    WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: time adder

    How about DateDiff()?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    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

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: time adder

    DateAdd

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    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

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: time adder

    try datediff instead
    VB Code:
    1. 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:
    1. Dim t As Date
    2. x = DateDiff("n", "01:30", "2:35") ' returns 65
    3. 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
  •  



Click Here to Expand Forum to Full Width