VB6Runtime / Library / Datetime / date_statement

VB6 Library Reference

Date Statement

Sets the current system date.

Syntax

Date = dateexpression

Parts

Return Value

None. This is a statement, not a function.

Remarks

The Date statement sets the system date to the value of dateexpression. In VB6 on Windows this modifies the real system clock and requires administrator privileges. In this runtime the behavior depends on the allow_system_clock flag: - Default (system clock allowed): The date is written to the real system clock via platform APIs. Subsequent Date and Date$ calls return the real system date. - Internal-only mode: The date is stored in an offset-based mock clock that advances in real time from the set point. The real system clock is never modified. - Date Storage: Internally, dates are stored as Double values representing the number of days since December 30, 1899. - Date Range: January 1, 100 through December 31, 9999. - Permissions: On real VB6, changing the system date requires administrator privileges. - Date Function: Use the Date function (without assignment) to retrieve the current system date. - Date$ Function: Use Date$ to retrieve the current date as a string. - Error Handling: Invalid date values generate a runtime error (error 13, type mismatch).

Examples

Set Date to Specific Value

Date = #1/1/2025#

Set Date Using Variable

Dim newDate As Date
newDate = #6/15/2025#
Date = newDate

Set Date Using DateSerial

Date = DateSerial(2025, 12, 25)

Set Date Using String

Date = "January 1, 2025"

Set Date Using DateAdd

Date = DateAdd("d", 30, Date)

Set Date from User Input

Dim userDate As String
userDate = InputBox("Enter new date (MM/DD/YYYY):")
If IsDate(userDate) Then
    Date = userDate
Else
    MsgBox "Invalid date format"
End If

Set Date with Error Handling

On Error Resume Next
Date = #1/1/2025#
If Err.Number <> 0 Then
    MsgBox "Failed to set date: " & Err.Description
End If
On Error GoTo 0

Reset Date to Current System Date

' Clear any override by setting to today's real date
Date = Date

Common Errors

Best Practices

See Also

References

← Back to Datetime | View all statements