Q(uick)BASIC Function: TimeSerial#

Quick View

TimeSerial#

A function that returns a serial number that represents the time of the arguments

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • TimeSerial# (hour%, minute%, second%)
Description/Parameter(s)
hour% An hour between 0 (12:00 AM) and 23 (11:00 PM), inclusive.
minute% A minute between 0 and 59, inclusive.
second% A second between 0 and 59, inclusive.
  • You can use negative numbers as arguments, as long as the resulting serial number is positive. For example, to find the serial number for the time 50 seconds before 2:00:02, you could use:
    TimeSerial#(2,0,2-50)

Usage Notes

Important

  • To use TimeSerial# in the QBX environment, use the DTFMTER.QLB Quick library. To use TimeSerial# 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:
    FilenameCompiler options
    DTFMTER.LIB80x87 or emulator math; DOS or OS/2 real mode
    DTFMTAR.LIBAlternate math; DOS or OS/2 real mode
    DTFMTEP.LIB80x87 or emulator math, OS/2 protected mode
    DTFMTAP.LIBAlternate math; OS/2 protected mode
  • The DATIM.BI header file contains the necessary declarations for using TimeSerial#.
  • 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")