Using CALL INTERRUPT to Retrieve Current Date In Basic (93924)



The information in this article applies to:

  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q93924

SUMMARY

The MS-DOS command line function DATE returns the day of the week as well as the date in the MM-DD-YY format. This information can also be obtained from a Basic program by using the CALL INTERRUPT routine.

MORE INFORMATION

MS-DOS Interrupt 21H function 2AH (get date) returns the following:

  • Day of the week in the AX register; 0 through 6 corresponds with Sunday through Saturday
  • Year in the CX register; 1980 through 2099
  • Month in the DH register; 1 through 12
  • Day in the DL register; 1 through 28,29,30,31 depending on the month
Information on ROM BIOS Interrupt 21H with function 2AH can be found in the following book:

"The New Peter Norton Programmer's Guide to the IBM PC & PS/2; the Ultimate Reference Guide to the Entire Family of IBM Personal Computers" by Peter Norton and Richard Wilton, published by Microsoft Press (1985). See page 339.

Code Example

To run the following sample program in the QB.EXE or QBX.EXE environment, you must invoke the environment with the /L switch to load the default Quick library. For example:

QB /L (Use this MS-DOS command line if you are using QuickBasic.)
QBX /L (Use this MS-DOS command line if you are using Basic PDS.)

To make an .EXE file from MS-DOS, the compiled program must be LINKed with the library QB.LIB (or QBX.LIB, if you are using Basic PDS).
' Use the following include file for QuickBasic for MS-DOS:
REM $INCLUDE: 'qb.bi'
' Use the following include file for Basic PDS for MS-DOS:
REM $INCLUDE: 'qbx.bi'

DIM DayName(0 TO 6) AS STRING * 9
DayName(0) = "Sunday"
DayName(1) = "Monday"
DayName(2) = "Tuesday"
DayName(3) = "Wednesday"
DayName(4) = "Thursday"
DayName(5) = "Friday"
DayName(6) = "Saturday"

DIM InRegs AS RegType
DIM OutRegs AS RegType

CLS

InRegs.AX = &H2A00                'Function 2AH  Get Date.
CALL INTERRUPT(&H21, InRegs, OutRegs)

DayWeek% = OutRegs.AX AND &HFF
Month% = (OutRegs.DX AND &HFF00) / &H100
Day% = OutRegs.DX AND &HFF
Year% = OutRegs.CX
<BR/><BR/>
DateString$ = DayName(DayWeek%) + STR$(Month%) + "-" +
LTRIM$(STR$(Day%)) + "-" + LTRIM$(STR$(Year%))
PRINT DateString$
END
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB93924