Microsoft KB Archive/101022: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 14: Line 14:
* Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
* Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a


To convert a number of hours expressed as a numeric value to a time string of the form "HH:MM:SS", you can use the following user-defined function (UDF):
To convert a number of hours expressed as a numeric value to a time string of the form "HH:MM:SS", you can use the following user-defined function (UDF):


<pre>  * NTOT(&lt;expN&gt;)
<pre>  * NTOT(&lt;expN&gt;)
   * Returns a string in the form &quot;HH:MM:SS&quot;.
   * Returns a string in the form "HH:MM:SS".
   * &lt;expN&gt; is a number of hours expressed as a numeric value between
   * &lt;expN&gt; is a number of hours expressed as a numeric value between
   * 0 and 24. If &lt;expN&gt; is negative or greater than 24, the null
   * 0 and 24. If &lt;expN&gt; is negative or greater than 24, the null
Line 27: Line 27:


   IF number &lt; 0 OR number &gt; 24          &amp;&amp; Error checking
   IF number &lt; 0 OR number &gt; 24          &amp;&amp; Error checking
       RETURN &quot;&quot;
       RETURN ""
   ENDIF
   ENDIF


Line 36: Line 36:


   * Convert values to strings and pad with leading zeros if necessary
   * Convert values to strings and pad with leading zeros if necessary
   hourstring=IIF( hours&gt;9, LTRIM(STR(hours)), &quot;0&quot;+LTRIM(STR(hours)) )
   hourstring=IIF( hours&gt;9, LTRIM(STR(hours)), "0"+LTRIM(STR(hours)) )
   minutestring=IIF( minutes &gt; 9, LTRIM(STR(minutes)),</pre>
   minutestring=IIF( minutes &gt; 9, LTRIM(STR(minutes)),</pre>
&quot;0&quot;+LTRIM(STR(minutes)) )
"0"+LTRIM(STR(minutes)) )
<pre>  secondstring=IIF(seconds &gt; 9, LTRIM(STR(seconds)),</pre>
<pre>  secondstring=IIF(seconds &gt; 9, LTRIM(STR(seconds)),</pre>
&quot;0&quot;+LTRIM(STR(seconds)) )
"0"+LTRIM(STR(seconds)) )
<pre>  * Return completed string in the form &quot;HH:MM:SS&quot;
<pre>  * Return completed string in the form "HH:MM:SS"
   RETURN ( hourstring +':' + minutestring + ':' + secondstring )
   RETURN ( hourstring +':' + minutestring + ':' + secondstring )
</pre>
</pre>

Revision as of 09:19, 20 July 2020

How to Convert a Numeric Value to HH:MM:SS Time Format

ID: Q101022

2.50 2.50a | 2.00 2.50 2.50a

WINDOWS         | MS-DOS

kbprg The information in this article applies to:

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

To convert a number of hours expressed as a numeric value to a time string of the form "HH:MM:SS", you can use the following user-defined function (UDF):

   * NTOT(<expN>)
   * Returns a string in the form "HH:MM:SS".
   * <expN> is a number of hours expressed as a numeric value between
   * 0 and 24. If <expN> is negative or greater than 24, the null
   * string is returned.

   FUNCTION NTOT
   PARAMETERS number
   PRIVATE hours,minutes,seconds,hourstring,minutestring,secondstring

   IF number < 0 OR number > 24          && Error checking
      RETURN ""
   ENDIF

   * Break number down into hour, minute, and second values
   hours=INT(number)
   minutes=INT((number-hours)*60)
   seconds=( ((number-hours)*60) - minutes ) * 60

   * Convert values to strings and pad with leading zeros if necessary
   hourstring=IIF( hours>9, LTRIM(STR(hours)), "0"+LTRIM(STR(hours)) )
   minutestring=IIF( minutes > 9, LTRIM(STR(minutes)),

"0"+LTRIM(STR(minutes)) )

   secondstring=IIF(seconds > 9, LTRIM(STR(seconds)),

"0"+LTRIM(STR(seconds)) )

   * Return completed string in the form "HH:MM:SS"
   RETURN ( hourstring +':' + minutestring + ':' + secondstring )

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.x TTON KBCategory: kbprg KBSubcategory: FxprgGeneral

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

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