Name
DateSerial Function
Syntax
DateSerial(year,month,day)
-
year Use: Required
Data Subtype: Integer
Number between 100 and 9999, inclusive, or a numeric expression.
-
month Use: Required
Data Subtype: Integer
Any numeric expression to express the month between 1 and 12.
-
day Use: Required
Data Subtype: Integer
Any numeric expression to express the day between 1 and 31.
Return Value
A Variant of subtype Date.
Description
Returns a Variant of subtype Date from the three date components (year, month, and day). For the function to succeed, all three components must be present, and all must be numeric values. The value returned by the function takes the short date format defined by the Regional Settings applet in the Control Panel of the client machine.
Rules at a Glance
If the value of a particular element exceeds its normal limits,
DateSerialadjusts the date accordingly. For example, if you triedDateSerial (96,2,31)—February 31, 1996—DateSerialreturns March 2, 1996.You can specify expressions or formulas that evaluate to individual date components as parameters to
DateSerial. For example,DateSerial(98,10+9,23)returns 23 March 1999. This makes it easier to useDateSerialto form dates whose individual elements are unknown at design time or that are created on the fly as a result of user input.
Example
Dim iYear, iMonth, iday iYear = 1987 iMonth = 3 + 11 iday = 16 MsgBox DateSerial(iYear, iMonth, iday)
Programming Tips & Gotchas
If any of the parameters exceed the range of the Integer datatype (-32,768 ...
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