Skip to Main Content
VBScript in a Nutshell, 2nd Edition
book

VBScript in a Nutshell, 2nd Edition

by Paul Lomax, Matt Childs, Ron Petrusha
March 2003
Intermediate to advanced content levelIntermediate to advanced
512 pages
14h 30m
English
O'Reilly Media, Inc.
Content preview from VBScript in a Nutshell, 2nd Edition

Name

CDate Function

Syntax

CDate(expression)
expression

Use: Required

Data Type: String or Numeric

Any valid date expression.

Return Value

expression converted into a Date type.

Description

Converts expression to a Date type. 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 expression is 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 expression is 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

  • CDate accepts both numerical date expressions and string literals. You can pass month names into CDate in either complete or abbreviated form; for example, “31 ...

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.
Start your free trial

You might also like

VBScript in a Nutshell

VBScript in a Nutshell

Matt Childs, Paul Lomax, Ron Petrusha
Microsoft® PowerShell, VBScript and JScript® Bible

Microsoft® PowerShell, VBScript and JScript® Bible

William R. Stanek, James O'Neill, Jeffrey Rosen

Publisher Resources

ISBN: 0596004885Errata Page