Returns a Date value representing a specified year, month, and day, with the time information set to midnight (00:00:00).
Public Function DateSerial( _ ByVal [Year] As Integer, _ ByVal [Month] As Integer, _ ByVal [Day] As Integer _ ) As DateTime
Under Windows® 98 or Windows 2000, two-digit years for the Year argument are interpreted based on user-defined machine settings. The default settings are that values from 0 through 29 are interpreted as the years 20002029, and values from 30 through 99 are interpreted as the years 19301999. For all other Year arguments, use a four-digit year; for example, 1924.
Earlier versions of Windows interpret two-digit years based on the defaults described previously. To be sure the function returns the proper value, use a four-digit Year.
The following example demonstrates negative, zero, and positive argument values. Here, the DateSerial function returns a Date representing the day before the first day of March in the year 10 years before the current year; in other words, the last day of February ten years ago.
Dim EndFeb As Date = DateSerial(-10, 3, 0)
If either Month or Day exceeds its normal range, it is applied to the next larger unit as appropriate. For example, if you specify 32 days, it is evaluated as one month and from one to four days, depending on the value of Month. If Year is greater than 9999, or if any argument is outside the range -2,147,483,648 through 2,147,483,647, an ArgumentException error occurs. If the date specified by the three arguments is earlier than 00:00:00 on January 1 of the year 1, or later than 23:59:59 on December 31, 9999, an ArgumentOutOfRangeException error occurs.
The Date data type includes time components. DateSerial sets all of these to 0, so the returned value represents the beginning of the calculated day.
Since every Date value is supported by a DateTime structure, its methods give you additional options in assembling a Date value. For example, you can use one of the overloaded DateTime constructors to populate a Date variable using the desired combination of components. The following example sets NewDateTime
to May 6, 1978 at one tenth of a second before 8:30 in the morning:
Dim NewDateTime As Date = New Date(1978, 5, 6, 8, 29, 59, 900)
This example uses the DateSerial function to return the date for the specified year, month, and day.
Dim MyDate As Date ' MyDate contains the date for February 12, 1969. MyDate =DateSerial(
1969,
2,
12)
' Return a date.
DateValue Function | Day Function | Month Function | Now Property | TimeSerial Function | TimeValue Function | Weekday Function | Year Function | Date Data Type |