Visual Basic Language Reference  

DateString Property

Returns or sets a String value representing the current date according to your system.

Public Property DateString As String

Exceptions/Errors

Exception type Error number Condition
InvalidCastException 5 Invalid cast.

Remarks

DateString always returns the system date as "MM-dd-yyyy", which uses the abbreviated month name. The accepted formats for setting the date are "M-d-yyyy", "M-d-y", "M/d/yyyy", and "M/d/y".

If you attempt to set DateString with an invalid value, an InvalidCastException occurs.

To get or set the current system time as a String, use the TimeString property.

To access the current system date as a Date, use the Today property.

Example

This example uses the DateString property to display the current system date.

MsgBox("The current date is " & DateString)

See Also

Now Property | TimeString Property | Today Property | System Namespace | DateTime Structure | ArgumentException