Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Time Related Commands Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example calculates the time between now and midnight tonight. The
' time information is displayed using the TIMEVALUE, TIMESERIAL, HOUR,
' MINUTE, and SECOND functions.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
CLS ' Clear the screen
' Get a time value for midnight tonight - 1 second.
Midnight = TIMEVALUE("23:59:59")
' Get a time value for right now.
Instant = NOW
' Get the difference in hours, minutes, seconds.
HourDiff% = HOUR(Midnight) - HOUR(Instant)
MinuteDiff% = MINUTE(Midnight) - MINUTE(Instant)
' Add in the odd second between 23:59:59 and midnight.
SecondDiff% = SECOND(Midnight) - SECOND(Instant) + 1
' Adjust so that seconds and minutes are less than 60.
IF SecondDiff% = 60 THEN
MinuteDiff% = MinuteDiff% + 1
SecondDiff% = 0
END IF
IF MinuteDiff% = 60 THEN
HourDiff% = HourDiff% + 1
MinuteDiff% = 0
END IF
' Calculate a total of seconds between now and midnight.
TotalMinDiff = (HourDiff% * 60) + MinuteDiff%
TotalSecDiff = (TotalMinDiff * 60) + SecondDiff%
' Put the difference back into a standard time format.
TotalDiff = TIMESERIAL(HourDiff%, MinuteDiff%, SecondDiff%)
' Display results.
CLS
PRINT "There are a total of"; TotalSecDiff; "seconds until midnight."
PRINT "That translates to"; HourDiff%; "hours,"; MinuteDiff%;
PRINT "minutes, and"; SecondDiff%; "seconds."
PRINT
PRINT "The difference can also be expressed in standard time notation as:"
PRINT FORMAT$(TotalDiff, "hh:mm:ss")