bas7ex.hlp (Topic list)
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 Functions Programming 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.
 
'Note: To run this example you must use a Quick library that includes
'the procedures contained in the date/time/format library files. The
'following $INCLUDE files must also be present.
 
'$INCLUDE: 'DATIM.BI'
'$INCLUDE: 'FORMAT.BI'
 
'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 FormatD$(TotalDiff#, "hh:mm:ss")