Seconds(), Sys(2)

SECONDS() returns a numeric value of the number of seconds since midnight, with a resolution of one millisecond. SYS(2) returns a character string of the same number, formatted as five digits with no decimal places.

Usage

nRetVal = SECONDS()
cTime = SYS(2)
Very useful for benchmarking the time to complete a task—record the start time, do the task, then subtract the start time from the end time to calculate the duration of the task. Don't confuse this with the SEC() function used to extract the seconds portion of a datetime.

The SECONDS() function grabs the time when FoxPro starts and stores it in some hidden nook or cranny. Changing the system time while FoxPro is running is not reflected in the SECONDS() function, although TIME() and DATETIME() do seem to pick it up.


Strangely enough, the SECONDS() function, while ignoring other changes, does note that midnight has passed during the current session and resets SECONDS() to zero. This can be very useful if you are capturing seconds since midnight in an application that might need to run for several days. This was a notorious 2.x bug, squashed finally in 3.0.


SYS(2) does reflect changes made to the system time while Visual FoxPro is running, although we don't advise doing this—it can make it awfully difficult to determine which source code is the most recent when the time keeps shifting! SYS(2), like SECONDS(), will reset on the stroke of midnight.

Example

lcStopTime = SYS(2)
lnStartTime = SECONDS()

See Also

DateTime(), Sec(), Time()


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .