See Also Example
Sets the current system date.
Syntax
Date[$] = expression
Remarks
For the Date statement, expression must be a String formatted as a date or a Variant If expression is a String (or a Variant of VarType 8) that contains only numbers delimited by valid date separators, Date recognizes the order for month, day, and year according to the Short Date format in the International section of the Windows Control Panel. Date also recognizes unambiguous dates that contain month names, either in long or abbreviated form. For example, in addition to recognizing 12/30/1991 and 12/30/91, Date recognizes December 30, 1991; Dec 30, 1991; 30-Dec-1991; and 30 December 91. If expression is not already a Variant of VarType 7, Date attempts to convert it. If it can't be converted to a date from January 1, 1980 through December 31, 2099, an error occurs.
For Date$, expression must have one of the following forms, where mm (01-12) and dd (01-31) are the month and day and yy or yyyy (1980-2099) is the year:
mm-dd-yy
mm-dd-yyyy
mm/dd/yy
mm/dd/yyyy
If you use the Date[$] statement to set the date with versions of MS-DOS earlier than 3.3, the change remains in effect only until you change it again or turn off your computer. Many computers have a battery-powered CMOS RAM that retains date and time information when the computer is turned off. However, to permanently change the date on computers running earlier versions of MS-DOS, you may have to use your Setup disk or perform some equivalent action. Refer to the documentation for your particular system.
Date, Date$ Functions
Time, Time$ Functions
Time, Time$ Statements
Date, Date$ Statements Example
The example uses the Date statement to set the computer system date to a new date entered by the user. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Default, Msg, NewDate ' Declare variables.
Msg = "Enter a new date in the form mm-dd-yyyy"
Default = Date ' Current date.
Newdate = InputBox(Msg, "", Default) ' Get user input.
If Len(Newdate) > 0 Then ' Check if valid.
Date = Newdate ' Set date.
Msg = "System date set to "
Msg = Msg & Format(DateValue(Newdate), "dddd, mmmm d, yyyy")
Else
Msg = "You did not enter a valid date."
End If
MsgBox Msg ' Display message.
End Sub