Syntax
DateSerial(Year, Month, Day)
Remarks
Returns the serial number of the specified date. The serial number corresponds to the number of days between December 30, 1899, and the specified date, up to December 31, 4095. For example, the serial number 1 corresponds to December 31, 1899. DateSerial() generates an error if the specified date is beyond the allowable range.
Argument | Explanation | |
Year | A number between 0 (zero) and 4095, inclusive, or a numeric expression. To specify a year in the range 1900 to 1999, you can give the last two digits of the year; to specify the year 1899 or a year after 1999, give all four digits of the year. | |
Month | A number between 1 and 12, inclusive, or a numeric expression representing the month of the year. | |
Day | A number between 1 and 31, inclusive, or a numeric expression representing the day of the month. |
Example
This example prompts the user to enter a date and then displays a message box to indicate the day of the week corresponding to that date:
Dim days$(7) days$(1) = "Sunday" : days$(2) = "Monday" days$(3) = "Tuesday" days$(4) = "Wednesday" days$(5) = "Thursday" days$(6) = "Friday" days$(7) = "Saturday" datestring$ = Inputbox$("Please enter the date for which " + \ "you want to determine the weekday (mm/dd/yy):") monthnum = Val(Left$(datestring$, 2)) daynum = Val(Mid$(datestring$, 4, 2)) yearnum = Val(Right$(datestring$, 2)) dayofweek = DateSerial(yearnum, monthnum, daynum) MsgBox "The day of the week is " + days$(Weekday(dayofweek)) + "."
See Also
Date$(), DateValue(), Day(), Month(), Now(), TimeSerial(), Today(), Year()