CVDate Function

See Also2G5SLVJ              Example43R6X3>Low

Converts an expression to a Variant8PHEAW3 of VarType7A68ZTZ 7 (Date).

Syntax

CVDate(expression)

Remarks

The argument expression must be a string expression1330R89 or a numeric expression71RISN that can be interpreted as a date.  The acceptable range for date information is January 1, 100 A.D. (-657434) through December 31, 9999 A.D. (2958465).

The following table identifies the action that occurs as a result of evaluating expression.

If expression is this type

CVDate takes this action

 

A numeric expression

Checks range. if not in range, generates a run time error; otherwise converts expression to a date.

A string expression that looks like a date, for example,  "1 May 1992 12:00 PM"

Converts expression to a date.

A string expression that looks like a number, for example, "33664"

Converts expression to a number.
Checks range.  If not in range, generates a run-time error; otherwise converts expression to a date.

Any other string expression

Generates a run-time error.

For string expressions, CVDate recognizes date formats that can be set in the International section of the WIN.INI file using the Microsoft Windows Control Panel.  However, CVDate cannot recognize a long date format if it also contains the day-of-the-week string.

If a string expression contains only numbers, CVDate may not be able to determine the correct order of day, month, and year if it is provided in a format other than one of the current WIN.INI date settings.

 

Note   You may be able to use the IsDate function to determine if either a numeric expression or a string expression that looks like a date can actually be converted to a date.  However, IsDate cannot determine if a string that looks like a number can be converted to a date.

 

 

Note   When converting from a number to a date, Visual Basic converts any fractional part of the number to a time of day, starting at midnight.

 


See Also

Data Type Conversion Functions1JQNQGO

IsDate Function9B784K


CVDate Function Example

The example returns a Variant of VarType 7 containing the date serial for your birth date.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim BirthDate, Msg, TestDate          ' Declare variables.

   Msg = "Enter your birth date using any form you like."

   Do

      TestDate = InputBox(Msg)           ' Get user date.

   Loop Until IsDate(TestDate)           ' Test for valid date.

   BirthDate = CVDate(TestDate)          ' Make Variant.

   Msg = "The short form of your birth date is " & BirthDate

   MsgBox Msg                            ' Display message.

End Sub