Q(uick)BASIC Statement: DATE$

Quick View

DATE$

A statement that uses DOS to set the current date

Worth knowing

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

Syntax
  • DATE$
  • DATE$ = stringexpression$
Description/Parameter(s)

The DATE$ function returns the computer's current system date.
The DATE$ statement sets the current system date on your computer.

stringexpression$ The date in one of the following forms: mm-dd-yy, mm-dd-yyyy, mm/dd/yy, mm/dd/yyyy.
The DATE$ function returns a string in the form mm-dd-yyyy.
Example
PRINT DATE$ DATE$ = "01-01-90" 'Note: The new system date remains in effect until ' you change it again. PRINT "Date set to "; DATE$

See also:

Syntax
  • DATE$ = stringexpression
Description/Parameter(s)

The DATE$ statement is the complement of the DATE$ function.

The stringexpression must have one of the following forms, where mm (01-12) and dd (01-31) are the month and day, and yy and yyyy (1980-2099) are the year:

  • mm-dd-yy
  • mm-dd-yyyy
  • mm/dd/yy
  • mm/dd/yyyy
Example

This example prompts you to supply the month, date, and year, then resets the system date on your computer.

' Note: Run this program with caution. If you change the system date, ' any files you create or revise will be stamped with the new date. ' Make sure to reset the system date to the current date. PRINT "Enter the date below (default year is 1989)." INPUT " Month: ",Month$ INPUT " Date: ",Day$ INPUT " Year: ",Year$ IF Year$ = "" THEN Year$ = "89" DATE$ = Month$ + "/" + Day$ + "/" + Year$
Syntax
  • DATE$ = stringexpression$
Description/Parameter(s)
stringexpression$ The date in one of the following forms:
mm-dd-yy, mm-dd-yyyy, mm/dd/yy, or mm/dd/yyyy
where:
mm (01-12) Is the month.
dd (01-31) Is the day.
yy or yyyy (1980-2099) Is the year.

The DATE$ statement sets the current date in your computer's system. It is the complement of the DATE$ function, which returns the current date.

Usage Notes

  • When you change the date in your computer's system with the DATE$ statement, the change remains in effect until you change the date again or reboot your computer.
Example

The following example displays the current date by converting the date returned by the DATE$ function. The names of months are stored in DATA statements and assigned to a string variable using the READ statement.

'Get the date. C$ = <b>DATE$</b> 'Use VAL to find the month from the string returned by <b>DATE$</b>. FOR I% = 1 TO VAL(C$) READ Month$ NEXT DATA January, February, March, April, May, June, July DATA August, September, October, November, December 'Get the day. Day$ = MID$(C$, 4, 2) IF LEFT$(Day$, 1) = "0" THEN Day$ = RIGHT$(Day$, 1) 'Get the year. Year$ = RIGHT$(C$, 4) PRINT "Today is "; Month$; " "; Day$; ", "; Year$

Sample Output:

Today is September 21, 1989