Q(uick)BASIC Function: TimeValue#

Quick View

TimeValue#

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

Worth knowing

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

Syntax
  • TimeValue# (time$)
Description/Parameter(s)
time$ A time between 0:00:00 (12:00:00 AM) and 23:59:59 (11:59:59 PM), inclusive. Time can be entered as "2:24PM" or "14:24".
Date information, if included in the argument, is ignored.

Usage Notes

Important

  • To use TimeValue# in the QBX environment, use the DTFMTER.QLB Quick library. To use TimeValue# 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 function declarations for using TimeValue#.
  • 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")