Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Date Functions Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
'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"