Q(uick)BASIC Function: DateSerial#

Quick View

DateSerial#

Returns a serial number that represents the date of the arguments

Worth knowing

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

Syntax
  • DateSerial# (year%, month%, day%)
Description/Parameter(s)
year% A year between 1753 and 2078, inclusive.
month% A month between 1 and 12, inclusive.
day% A day between 1 and 31, inclusive.
  • The year% values 0-178 can be used for the years 1900-2078. For all other years, use the complete 4-digit year (for example, 1800).
  • Arguments outside of the ranges shown on the Syntax screen are evaluated to calculate a valid date. For example:

  • TheDate# = DateSerial#(89, 13, 1)

  • The month% argument of 13 evaluates to the first month of the next Year: January 1, 1990!

  • Values that equate to a serial number outside of the range of -53688 to 65380 produce the error message, "Illegal function call." This translates to an actual date range of January 1, 1753 to December 31, 2078 inclusive.
  • You can use negative numbers as arguments. For example, to find the serial number for the date one week before 9/1/89, you could use:

  • DateSerial#(89,9,1-7)

Usage Note

Important

  • To use DateSerial# in the QBX environment, use the DTFMTER.QLB Quick library. To use DateSerial# 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 DateSerial#.
  • 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 uses the DateSerial# function to calculate the date value for January 1st in the year of your birth. You are then told what day of the week January 1st fell on in that year. Information is displayed using Year& and Weekday&functions.
Note: To run this example you must use a Quick library that includes the procedures contained in the date/time library files. The DATIM.BI include file must also be present.

'$INCLUDE: 'DATIM.BI' OPTION BASE 1 DEFINT A-Z DIM DayOfWeek(7) AS STRING 'Initialize the array. FOR I = 1 TO 7 READ DayOfWeek$(I) NEXT I INPUT "What are the last two digits of your birth year"; Birthyear 'Calculate January 1st of birthyear. Jan1Date# = DateSerial#(Birthyear, 1, 1) 'Display results. PRINT "January 1,"; Year&(Jan1Date#); "fell on a "; PRINT DayOfWeek$(Weekday&(Jan1Date#)) DATA "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" DATA "Friday", "Saturday", "Sunday"