How to: Hold Date and Time Values in a Variable

A variable holds date and time values if you declare it to be of data type Date.

A variable of the Date Data Type (Visual Basic) can hold date values ranging from January 1 of the year 0001 through December 31 of the year 9999, and time values from 12:00:00 AM (midnight) through 11:59:59 PM.

The Date data type always holds both a date value and a time value. If you do not assign a time value to a Date variable, it defaults to the start of the day, that is, midnight. If you do not assign a date value to a Date variable, it defaults to January 1, 0001.

To hold dates in a variable

  1. Declare the variable with a Dim Statement (Visual Basic).

  2. Follow the variable name with an As clause.

  3. Follow the As keyword with the Date keyword.

See Also

Concepts

Data Types in Visual Basic

Type Characters

Reference

Data Type Summary (Visual Basic)

Single Data Type (Visual Basic)

Date Data Type (Visual Basic)

Other Resources

Elementary Data Types