Name
CDate Function
Syntax
CDate(expression)-
expression Use: Required
Data Subtype: String or Numeric
Any valid date expression.
Return Value
expression converted into a Variant with a
Date subtype.
Description
Converts expression to a Variant with a
Date subtype. The format of
expression—the order of day, month,
and year—is determined by the locale setting of your computer.
To be certain of a date being recognized correctly by
CDate, the month, day, and year elements of
expression must be in the same sequence as
your computer’s regional settings; otherwise the
CDate function has no idea that in the
expression “04/01/01,” 4 is
supposed to be the 4th of the month, not the month of April, for
example.
CDate also converts numbers to a date. The
precise behavior of the function, however, depends on the value of
expression :
If
expressionis less than or equal to 23 and includes a fractional component less than 60, the integer is interpreted as the number of hours since midnight, and the fraction is interpreted as the number of seconds.In all other cases, the integer portion of
expressionis converted to a date that interprets the integer as the number of days before (in the case of negative numbers) or after December 31, 1899, and its fractional part is converted to the time of day, with every .01 representing 864 seconds (14 minutes 24 seconds) after midnight.
Rules at a Glance
CDateaccepts both numerical date expressions and string literals. You can pass month names intoCDatein either ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access