This documentation is archived and is not being maintained.

Upgrade Recommendation: Use the Date Data Type for Storing Dates 

Earlier versions of Visual Basic support using the Double data type to store and manipulate dates. You should not do this in Visual Basic 2005, because dates are not internally stored as doubles. For example, the following is valid in Visual Basic 6.0, but may cause a compile error in Visual Basic 2005:

Dim dbl As Double
Dim dat As Date
dat = Now
'BAD: Date can't be assigned to a double
dbl = dat
'BAD: Double can't be used in date functions
dbl = DateAdd("d", 1, dbl)
'BAD: CDate can't convert a double to a date
dat = CDate(dbl)

The .NET Framework provides the ToOADate and FromOADate functions to convert between doubles and dates. However, when your project is upgraded to Visual Basic 2005, it is difficult to determine the intention of code that uses doubles to store dates. To avoid unnecessary modifications to your code in Visual Basic 2005, always use the Date data type to store dates.

See Also