CDate Function


CDate Function

Syntax

     Dim result As Date = CDate  (expression) 


expression (required; String or Numeric)

Any valid representation of a date and time

Description

The CDate function converts expression to the Date data type. The interpretation of the date components in the expression is based on the locale setting of the local computer.

Usage at a Glance

  • The supported date range of the Date data type is from January 1, 1 AD to December 31, 9999 AD in the Gregorian calendar.

  • You can check that a date expression is valid using the IsDate function.

  • Passing an empty string to CDate generates an error.

  • This function does not support named arguments.

  • The CDate function makes some guesses about how to interpret invalid date formats so they are still usable. For example, on systems that use the "m/d/yyyy" date component arrangement, a source expression of "30/12/97" will still result in December 30, 1997, since CDate understands that "30" is an invalid month, but "12" is valid. This can cause problems if your code expects an error to be generated from this input.

  • The CDate function guesses the century if a two-digit year is supplied. It sometimes places it in the previous century and sometimes in the current century. In general, two-digit years under 30 appear in the current century, while those 30 and beyond appear in the previous century.

  • If you do not specify a year, the CDate function uses the year from the current date on your computer.

See Also

DateValue Function, TimeValue Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net