Q(uick)BASIC Function: Minute&
Quick View
Minute&
A function that takes a date/time serial number and returns the minute
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- Minute& (serial#)
Description/Parameter(s)
serial# | A serial number that represents a date and/or time. |
Usage Notes
- For information on serial numbers, see ⮜ Serial Numbers ⮞.
Important
- To use Minute& in the QBX environment, use the DTFMTER.QLB Quick library. To use Minute& outside the QBX environment, link your program with the appropriate DTFMTxx.LIB file. Depending on the compiler options you chose when you installed BASIC, one or more of the following files will be available:
Filename | Compiler options |
DTFMTER.LIB | 80x87 or emulator math; DOS or OS/2 real mode |
DTFMTAR.LIB | Alternate math; DOS or OS/2 real mode |
DTFMTEP.LIB | 80x87 or emulator math, OS/2 protected mode |
DTFMTAP.LIB | Alternate math; OS/2 protected mode |
- The DATIM.BI header file contains the necessary function declarations for Minute&.
- For more information on using libraries, see "Creating and Using Quick Libraries" and "Using LINK and LIB" in the BASIC Programmer's Guide.
Example
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")