Date, Date$ (statements)


Date[$] = newdate


Sets the system date to the specified date.


The Date$ statement requires a string variable using one of the following formats:


Where MM is a two-digit month between 1 and 31, DD is a two-digit day between 1 and 31, and YYYY is a four-digit year between 1/1/100 and 12/31/9999.

The Date statement converts any expression to a date, including string and numeric values. Unlike the Date$ statement, Date recognizes many different date formats, including abbreviated and full month names and a variety of ordering options. If newdate contains a time component, it is accepted, but the time is not changed. An error occurs if newdate cannot be interpreted as a valid date.


This example saves the current date to Cdate$, then changes the date and displays the result. It then changes the date back to the saved date and displays the result.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()

  TheDate$ = Date
  Date = "01/01/95"
  MsgBox "Saved date is: " & TheDate$ & crlf & "Changed date is: " & Date
  Date = TheDate$
  MsgBox "Restored date to: " & TheDate$
End Sub

See Also

Date, Date$ (functions); Time, Time$ (statements).


If you do not have permission to change the date, runtime error 70 will be generated.

More information