Function Seconds() Foundation

Determines the number of seconds that have elapsed since midnight.

Seconds() --> nSeconds

The function Seconds() returns a numeric value in the range of 0.00 to 86399.99. It corresponds to the system time, in the form of the number of seconds that have elapsed since midnight. The return value has two decimal places, meaning that the function Seconds() measures time in increments of one hundredth of a second.


The environment function Seconds() provides the current system time in seconds. The smallest increment is 1/100 of a second. The function can be used for code profiling, where the system time is determined at the beginning and the end of a procedure and the elapsed time is calculated.

Code profiling with Seconds()

// In this example, the time to run two different pieces of code that 
// both create an array filled with random characters is compared using 
// Seconds(). This is a rudimentary form of profiling. 
// The first approach uses AAdd() to populate an empty array in a loop, 
// while the second approach creates a pre-dimensioned array using the 
// Array() function and then updates each existing array item. 

#define ARRAY_ITEMS  500000 

   LOCAL aArray 
   LOCAL nItem 
   LOCAL nSeconds1 
   LOCAL nSeconds2 
   LOCAL nSeconds3 

   nSeconds1 := Seconds() 
   aArray    := {} 
   FOR nItem := 1 TO ARRAY_ITEMS 
      AAdd(aArray, Chr(RandomInt(65, 90))) 

   nSeconds2 := Seconds() 
   aArray    := Array(ARRAY_ITEMS) 
   FOR nItem := 1 TO ARRAY_ITEMS 
      aArray[nItem] := Chr(RandomInt(65, 90)) 

   nSeconds3 := Seconds() 
   ? "Time for AAdd() :", nSeconds2 - nSeconds1 
   ? "Time for Array():", nSeconds3 - nSeconds2 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.