Results 1 to 8 of 8
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Handling Secongs

    I found this on the web



    For an Access database you can use this:
    VB Code:

    1. sqltotal = " Select id,Format(sum(use),'hh:nn:ss") from tel group by id "





    Seems interesting so I wondered about

    ? Format(387, "hh:nn:ss")
    or
    ? Format(sum(387), "hh:nn:ss")

    But neither work. Is it possible to use Format to return h:m:s from seconds ?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    ? Format(387, "hh:nn:ss") works - it just doesn't do what you think it should. Date/time values are floating point double data type where the right side is the fraction of a day after midnight and the left side is the number of days after 1899 (methinks 1901 for Mac). So formatting the number of days (387) since December 31 1899 as hour/minute/second values makes no sense. You would have to multiply the days by 24 to get the applicable number of hours, and that result by 60 to get the number of applicable minutes and so on.
    Try 387.50 and see what you get - and if it makes sense.
    Last edited by Micron; 10-11-2022 at 08:28 PM. Reason: correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    387.50 gave 12:00:00 which doesn't make a lot of sense (to me).
    The 387 are seconds (not days) if that changes things. I wondered if Access would do the arithmetic for me.
    Rather than my (poor) attempt which I don't think is quite right...
    Code:
    hr = Int(mySeconds \ 86400)
        min = Int(mySeconds \ 3600)
        min = min & Int(mySeconds \ 60)
        sec = mySeconds Mod 60
        Duration = hr & ":" & min & ":" & Format(sec, "0#")

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Format is not returning elapsed time, not exactly. It's trying to convert a number to clock time of day. However, time of day is essentially elapsed time from midnight.

    Consider Format(387 / 86400, "hh:nn:ss")

    Returns 00:06:27


    Also, your function code works.
    Last edited by June7; 10-12-2022 at 09:31 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    @June7 hey that's great! I didn't think my code in msg 3 was right. It seconds were e.g. 634448 it would return
    7:17610574:08
    The corrected code is
    Code:
     hr = mySeconds \ 3600
        y = mySeconds Mod 3600
        min = y \ 60
        sec = y Mod 60
        Debug.Print hr & ":" & Format(min, "0#") & ":" & Format(sec, "0#")
    which gives 176:14:08
    Format(634448 / 86400, "hh:nn:ss")
    =08:14:08. Maths is not my strong point most likely 634448 is way too large. Yes, if I make it 63448
    both methods return 17:37:28

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You got 12:00:00 because the .50 is half a day, which is 12 hours - especially when you're formatting such a number as time. So I don't think what I was saying had sunk in yet, but maybe it has now: 387 is 387 full days. You might think it was time but on the left side of the decimal, it's days. The right side is a fraction of a day - it's not seconds either. Time duration in hours, minutes and seconds is a bit of a bother in Access.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The Format expression only works as long as long as elapsed time is less than 24 hours - 86400 seconds.

    Ooops, I only tested your function with 387.

    Glad you got it figured out.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Thank you both. Yes I get it... and it'll help tidy up a few things. One more thing not to forget!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Error Handling
    By jimmyac23 in forum Access
    Replies: 3
    Last Post: 09-22-2014, 11:27 AM
  2. Handling yes/no fields
    By DavidS in forum Access
    Replies: 8
    Last Post: 08-07-2014, 12:07 AM
  3. error handling
    By slimjen in forum Forms
    Replies: 6
    Last Post: 03-13-2013, 11:49 AM
  4. On Error handling
    By rivereridanus in forum Access
    Replies: 2
    Last Post: 06-18-2012, 07:46 AM
  5. Help with Null value handling
    By Thumbs in forum Programming
    Replies: 3
    Last Post: 03-05-2012, 10:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums