See Also Example
Returns the current system date.
Syntax
Date[$]
Remarks
Date returns a Variant
Date$ returns a 10-character string of 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).
The return value of the Date$ function is equivalent to:
Format$(Now,"mm-dd-yyyy")
To set the system date, use the Date[$] statement.
CVDate Function
Date, Date$ Statements
Format, Format$ Functions
Now Function
Time, Time$ Functions
Time, Time$, Statements
The example uses the Date function to provide the default date for the input box when prompting the user for a new date. 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