Date Statement

Named Arguments

No

Syntax

Date = newdate

newdate

Use: Required

Date Type: String, Date, or Date Variant

Any valid date value.

Description

Sets the current system date.

Rules at a Glance

  • If you are setting the system date with numbers, as opposed to spelling the month, the sequence of Day, Month, and Year must be in the same sequence as the computer's regional settings.

  • If you are running under Microsoft Windows, the earliest system date you can set is January 1, 1980; the latest system date you can set is December 31, 2099.

  • For Microsoft Windows NT, the earliest and latest system dates are January 1, 1980 and December 31, 2079, respectively.

Example

Date = "31 January 1998"

Programming Tips and Gotchas

  • It's good programming practice to synchronize the dates across the machines in a multiuser environment, most commonly from the date on a server. This can be done at the operating-system level within the logon script or at application level using the Date and Time statements.

  • To bulletproof your application from curious users who want to see what happens if they change the regional settings to Danish, your application from being installed on a new system on which the system administrator forgets to change the regional settings to your locale, and a host of other ways in which the computer your application is running on has regional settings different from those you expect, you should never take a date for granted. Wherever possible, use the Format function to explicitly ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.