Q(uick)BASIC Function: Weekday&
Quick View
Weekday&
This function takes a date/time serial number and returns the day of the week
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- Weekday& (serial#)
Description/Parameter(s)
Usage Notes
- For information on serial numbers, see ⮜ Serial Numbers ⮞.
Important
- To use Weekday& in the QBX environment, use the DTFMTER.QLB Quick library. To use Weekday& 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 declarations for using Weekday&.
- 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 DateValue# function to convert a string to a date value. A calculation is then made that tells you the date of two weeks before and after your birth. Date information is displayed using the Weekday&, Day&, Month&, and Year& functions.
Note: To run this example you must use a Quick library that includes the procedures contained in the date/time library files. The following include file must also be present.
'$INCLUDE: 'DATIM.BI'
OPTION BASE 1
DEFINT A-Z
DIM DayOfWeek(7) AS STRING
DIM MonthOfYear(12) AS STRING
'Initialize the arrays.
FOR I = 1 TO 7
READ DayOfWeek(I)
NEXT I
FOR I = 1 TO 12
READ MonthOfYear(I)
NEXT I
INPUT "Enter your birthdate as MM/DD/YYYY "; Birthdate$
'Convert input date to numbers and create a complete date string.
BDateVal# = DateValue#(Birthdate$) 'Get the unique date value.
BDay$ = DayOfWeek$(Weekday&(BDateVal#)) + " " + MonthOfYear$(Month&(BDateVal#))
BDay$ = BDay$ + STR$(Day&(BDateVal#)) + "," + STR$(Year&(BDateVal#))
'Calculate a date 14 days earlier.
EDateVal# = BDateVal# - 14
'Put the date string together.
EDay$ = DayOfWeek$(Weekday&(EDateVal#)) + " " + MonthOfYear$(Month&(EDateVal#))
EDay$ = EDay$ + STR$(Day&(EDateVal#)) + "," + STR$(Year&(EDateVal#))
'Calculate a date 14 days later.
LDateVal# = BDateVal# + 14
'Put the date string together
LDay$ = DayOfWeek$(Weekday&(LDateVal#)) + " " + MonthOfYear$(Month&(LDateVal#))
LDay$ = LDay$ + STR$(Day&(LDateVal#)) + "," + STR$(Year&(LDateVal#))
'Display the results.
PRINT "You were born on "; BDay$; "."
PRINT
PRINT "What you may not have been able to immediately calculate was:"
PRINT
PRINT "Two weeks before your birth was "; EDay$; "."
PRINT "Two weeks after your birth was "; LDay$; "."
END
DATA "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"
DATA "Friday", "Saturday"
DATA "January", "February", "March", "April", "May", "June", "July"
DATA "August", "September", "October", "November", "December"