Results 1 to 9 of 9

Thread: Format time to decimals of seconds?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Format time to decimals of seconds?

    HI,all.

    how can i format the line of code bellow to have the decimals of seconds?

    VB Code:
    1. data_time = Format(datacurr_tempo, "hh:mm:ss")

    Thanks.

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

    Re: Format time to decimals of seconds?

    Give an example of the output you want?
    Last edited by penagate; Jul 10th, 2006 at 12:36 PM.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Format time to decimals of seconds?

    I think this is what he's looking for:
    90 seconds = 1min 30sec = 1.5 min....

    There isn't a way to do so with the format function.... you'll need to create your own. The calculation is simple though, get the number of seconds remaining and divide by 60... that will give you the decimal minute.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Format time to decimals of seconds?

    Hmm... I think he wants the output to looks something like 7:31:23.127 (hh:mm:ss.decimals). To be honest I don't think you can do that with the normal date/time functions since they don't contain fractions of a second.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Format time to decimals of seconds?

    Hi, Techgnome and Penagate.

    Thanks, but i think you guys didn´t understand what i´m looking for, what i want to do is
    save the system time in (hh:mm:ss:??) decimal of the seconds.

    Ok, if this is not possible how can i add a second to a given time?

    Thanks.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Format time to decimals of seconds?

    You can add a second to a time using the DateAdd function.
    VB Code:
    1. MsgBox DateAdd("s", 1, Now) 'add 1 second to the current date/time

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Format time to decimals of seconds?

    VB Code:
    1. Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
    2.  
    3. Private Type SYSTEMTIME
    4.     wYear As Integer
    5.     wMonth As Integer
    6.     wDayOfWeek As Integer
    7.     wDay As Integer
    8.     wHour As Integer
    9.     wMinute As Integer
    10.     wSecond As Integer
    11.     wMilliseconds As Integer
    12. End Type
    13.  
    14. Private Sub Form_Load()
    15.     Dim sTime As SYSTEMTIME
    16.     GetLocalTime sTime
    17.    
    18.     With sTime
    19.         Debug.Print .wHour & ":" & .wMinute & ":" & .wSecond & "." & .wMilliseconds
    20.     End With
    21. End Sub

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Format time to decimals of seconds?

    Thanks, Bushmobile.

    But now i have another question?

    - His possible to compare times in this way?,like for example:

    if time1>time2 then

    Thanks again?

  9. #9
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Format time to decimals of seconds?

    sure, just compare the numbers.

    however if you're looking to measure short periods of time then you should check out the GetTickCount API and the more accurate QueryPerformance APIs

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