Q(uick)BASIC Function: DATE$
Quick View
DATE$
A function that returns a string containing 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$
Description/Parameter(s)
The DATE$ function returns a ten-character string in the form mm-dd-yyyy, where mm is the month (01-12), dd is the day (01-31), and yyyy is the year (1980-2099).
Example
Note that the DATE$ function in the following example prints a zero in front of the month.
PRINT DATE$
Sample Output:
09-21-1988See also:
Syntax
- DATE$
Description/Parameter(s)
Returns | A 10-character string containing the current date in the form mm -dd - yyyy, where: |
mm | Is the month (01-12). |
dd | Is the day (01-31). |
yyyy | Is the year (1980-2099). |
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$ = DATE$
'Use VAL to find the month from the string returned by DATE$.
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, 1989See also: