Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/101796

From BetaArchive Wiki

How to Convert Time as "HH:MM:SS" to a Numeric Value

ID: Q101796

2.00 2.50 2.50a | 2.50 2.50a

MS-DOS          | WINDOWS

kbprg The information in this article applies to:

  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a

To convert a time string of the form "HH:MM:SS" to a numeric value, you must create a user-defined function (UDF). The following code is provided as an example.

   * TTON(<expC>)
   * Convert <expC> to a number of hours
   * Return value - Numeric
   * <expC> is a string of the form "HH:MM:SS". If <expC> doesn't
   * contain two colons (::), or time values are not in the range,
   * TTON returns -1.

   PARAMETERS timestr
   PRIVATE pos1,pos2,hours,minutes,seconds

   * Get position of first and second occurrences of ':'

   * Error checking
   IF pos1==0 OR pos2==0
      RETURN -1

   * Convert hh, mm and ss to numeric values and check for valid range
   hours = VAL(timestr)
   IF hours < 0 or hours > 24
      RETURN -1
   minutes = VAL(SUBSTR(timestr,pos1+1))   && from 1st ':' to 2nd ':'
   IF minutes < 0 or minutes > 59
      RETURN -1
   IF seconds < 0 or seconds > 59
      RETURN -1

   * Convert minutes and seconds to decimal values

   * Return total value of hours, minutes and seconds
   RETURN ( hours+minutes+seconds )

Additional reference words: FoxWin FoxDos 2.00 2.50 2.50a NTOT KBCategory: kbprg KBSubcategory: FxprgGeneral

Keywords          : FxprgGeneral 
Version           : 2.00 2.50 2.50a | 2.50 2.50a
Platform          : MS-DOS WINDOWS

Last Reviewed: April 30, 1996
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.