Convert Serial Number to Date Method
The Convert Serial Number to Date method converts a number to a date. It returns a date variable type that represents a date from January 1, 100, through December 31, 9999. For more information, see Variants.
To specify a relative date, you can use a numeric expression for any of the arguments. This expression evaluates to a number of days, months, or years before or after a specific date.
Format
DateSerial(year, month, day)
The following table describes the arguments that you can use with this method. As an option, you can use a numeric expression instead of an integer for each argument.
Argument | Description |
---|---|
year |
An integer that identifies a year in the range of 100 through 9999. |
month |
An integer that identifies a month in the range of 1 through 12. |
day |
An integer that identifies a day in the range of 1 through 31. |
Example
The following example finds the day of the week for November 7 in the year 2009:
Sub Button_Click
Dim checkdate As Variant, daynumber As Variant
Dim msgtext As String, checkday as Variant
Const checkyear = 2009
Const checkmonth = 11
checkday = 7
checkdate = DateSerial(checkyear,checkmonth,checkday)
daynumber = Weekday(checkdate)
msgtext = "November 7, 2009 falls on a " & _
Format(daynumber, "dddd")
End Sub