Results 1 to 7 of 7

Thread: [RESOLVED] Total Time

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    182

    Resolved [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

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

    Re: Total Time

    one way
    VB Code:
    1. x = DateDiff("s", value1, Value2)
    2. 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

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    182

    Re: Total Time

    Quote Originally Posted by westconn1
    one way
    VB Code:
    1. x = DateDiff("s", value1, Value2)
    2. 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??

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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.

    BOFH Now, BOFH Past, Information on duplicates

    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...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    182

    Re: Total Time

    format(cdate(<value2>)-cdate(<value1>),"hh:nn:ss")

    is that meant to be mm??

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width