Results 1 to 11 of 11
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Is there a function that will return time of day in seconds?

    Is there a function that will return time of day in seconds? One can certainly obtain the time formatted hh:mm:ss and do some arithmetic on the individual parts but there's got to be a simpler way.



    For Example:
    Code:
        strTime = Format(Time, "hh:mm:ss")
        TimeNow = 60 * 60 * Left(strTime, 2) + 60 * Mid(strTime, 4, 2) + Right(strTime, 2)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    How do you plan to use this value?
    Last edited by June7; 07-09-2019 at 02:15 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.

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Yes there is a simple way.
    The Timer function returns the number of seconds since midnight to 2d.p.
    For whole numbers use e.g. CInt(Timer) or Round(Timer,0)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    or you can use

    (now()-date())*86400

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    That will also work but perhaps Timer function is simpler

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    doesn't cInt need to be cLng?

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Oops. Yes it does need to be CLng. Well spotted

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Colin & Ajax, CLng(Timer) is exactly what I needed. How about dealing with a given string like "09:30:00 PM"? As it is now, I use the format function to convert such strings to "21:30:00" and use the cumbersome nonsense I posted in the OP.

    To answer June7's question, a new piece of code is calculating wait time parameters for the Timer function.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    Try:

    DateDiff("s", "00:00:00", Format(yourstring, "hh:mm:ss"))
    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.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I would not bother trying to parse through a string, just use something like

    cdbl(timevalue("09:30:00 PM"))*86400

    you do know that dates and times are stored as numbers and what you see e.g. 09:30:00 PM is just the result of a format property?

    the only time 09:30:00 PM is a string is a) it is passed to you as a string from a csv file or similar or from within a bunch of text or b)you make it a string by using the format function - as you did in your original post

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    you do know that dates and times are stored as numbers
    Yes, I'm quite familiar with that. More often than not I table dates using the integer portion or the double representation. Anyway thanks, I'll use your solution in that It's clear what's being done to whoever might be reading the code.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-27-2015, 06:18 PM
  2. Like pulling tenths of seconds "Time"?
    By clebergyn in forum Programming
    Replies: 2
    Last Post: 07-16-2015, 04:48 PM
  3. Replies: 4
    Last Post: 03-19-2015, 08:43 AM
  4. Replies: 1
    Last Post: 08-14-2012, 03:22 AM
  5. Function to return a set of records?
    By vicrauch in forum Access
    Replies: 2
    Last Post: 07-12-2011, 08:27 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