Microsoft KB Archive/93924

= Using CALL INTERRUPT to Retrieve Current Date In Basic =

Article ID: 93924

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 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:

&quot;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&quot; 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) = &quot;Sunday&quot; DayName(1) = &quot;Monday&quot; DayName(2) = &quot;Tuesday&quot; DayName(3) = &quot;Wednesday&quot; DayName(4) = &quot;Thursday&quot; DayName(5) = &quot;Friday&quot; DayName(6) = &quot;Saturday&quot;

DIM InRegs AS RegType DIM OutRegs AS RegType

CLS

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

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

Additional query words: QuickBas BasicCom 6.00 6.00b 7.00 7.10 2.00 2.01 3.00 4.00 4.00b 4.50

Keywords: KB93924

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.