Date-Variant

The variant has a special sub type called Variant/Date that can be used to hold dates.

Dim vValue1 As Variant 
Dim vValue2 As Variant
vValue1 = CDate(VBA.Date)
vValue2 = VBA.Date()

Variant/Date

All these functions return Variant/Date
DATE - Returns the current system date.
DATEADD - Returns the date with a specified time interval added.
DATESERIAL - Returns the date given a year, month and day.
DATEVALUE - Returns the date given a string representation of a date.
NOW - Returns the current system date and time.
TIME - Returns the current system time.
TIMESERIAL - Returns the time for a specific hour, minute and second.
TIMEVALUE - Returns the time given a string representation of a time.


CDATE vs CVDATE

CDATE - Returns an actual Date data type.
CVDATE - Returns a Variant data type whose sub type is Date. Only provided for backwards compatibility.


FORMAT

Because you will always want to use the FORMAT function to create a string containing a date, you should never use the DATE$ function.
Do not allow a variable of type Date to be implicitly converted into a string. In both cases use the FORMAT$ function to explicitly convert the date into a string


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext