DateSerial 函数DateSerial function

返回指定年月日的变量日期)。Returns a Variant (Date) for a specified year, month, and day.


DateSerial()DateSerial(year, month, day)

DateSerial 函数语法具有以下三个命名参数The DateSerial function syntax has these named arguments:

PartPart 说明Description
yearyear 必需;类型为 IntegerRequired; Integer. 介于 100 和 9999 之间(含 100 和 9999)的数字或者数字表达式Number between 100 and 9999, inclusive, or a numeric expression.
monthmonth 必需;类型为 IntegerRequired; Integer. 任何数字表达式。Any numeric expression.
为期day 必需;类型为 IntegerRequired; Integer. 任何数字表达式。Any numeric expression.


若要指定日期 (如1991年12月31日), 每个DateSerial 参数的数字范围应在该单位的接受范围内;即, 1–31 表示天, 1–12 表示月。To specify a date, such as December 31, 1991, the range of numbers for each DateSerial argument should be in the accepted range for the unit; that is, 1–31 for days and 1–12 for months. 但是, 也可以使用任何表示特定日期之前或之后的天数、月数或年数的数值表达式, 指定每个参数的相对日期。However, you can also specify relative dates for each argument by using any numeric expression that represents some number of days, months, or years before or after a certain date.

下面的示例使用数值表达式而不是绝对日期数。The following example uses numeric expressions instead of absolute date numbers. 下面的DateSerial函数返回一个日期, 该日期是第一天的前1 - 1一天 ()、八月之前8 - 2的两个月 ()、1990 - 1010 年前 1990 ();也就是说, 1980 年5月31日。Here the DateSerial function returns a date that is the day before the first day (1 - 1), two months before August (8 - 2), 10 years before 1990 (1990 - 10); in other words, May 31, 1980.

在 Windows 98 或 Windows 2000 中,根据用户定义的计算机设置将 year 参数解释为两位数的年份。Under Windows 98 or Windows 2000, two digit years for the year argument are interpreted based on user-defined machine settings. 默认设置是介于0和 29 (含) 之间的值被解释为2000年–2029。The default settings are that values between 0 and 29, inclusive, are interpreted as the years 2000–2029. 介于30和99之间的默认值被解释为年 1930–1999。The default values between 30 and 99 are interpreted as the years 1930–1999. 对于所有其他 year 参数,使用四位数的年份(例如 1800)。For all other year arguments, use a four-digit year (for example, 1800).

早期版本的 Windows 将根据前面所述的默认值解释两位数年份。Earlier versions of Windows interpret two-digit years based on the defaults described earlier. 为确保函数返回正确的值,请使用四位数的年份。To be sure the function returns the proper value, use a four-digit year.

当任何参数超出该参数接受的范围时,它根据需要递增到下一个更大的单位。When any argument exceeds the accepted range for that argument, it increments to the next larger unit as appropriate. 例如,如果您指定了 35 天,那么根据在一年中所处的时间段,将其计算为一个月又过了几天。For example, if you specify 35 days, it is evaluated as one month and some number of days, depending on where in the year it is applied. 如果任何单个参数超出了 -32,768 - 32,767 范围,将发生错误。If any single argument is outside the range -32,768 to 32,767, an error occurs. 如果这三个参数指定的日期超出了日期的可接受范围,将发生错误。If the date specified by the three arguments falls outside the acceptable range of dates, an error occurs.


对于_year_、 month_和_day, 如果**Calendar** 属性设置为公历, 则假定所提供的值为公历。For year, month, and day, if the Calendar property setting is Gregorian, the supplied value is assumed to be Gregorian. 如果 Calendar 属性设置为 Hijri,那么提供的值也假定为 Hijri。If the Calendar property setting is Hijri, the supplied value is assumed to be Hijri.

返回的日期部分采用当前 Visual Basic 日历的时间单位。The returned date part is in the time period units of the current Visual Basic calendar. 例如,如果当前日历为 Hijri,而要返回的日期部分为年份,那么年份值为 Hijri 年份值。For example, if the current calendar is Hijri and the date part to be returned is the year, the year value is a Hijri year. 对于参数_year_, 介于0和99之间的值 (含0和) 将被–解释为年 1400 1499。For the argument year, values between 0 and 99, inclusive, are interpreted as the years 1400–1499. 对于所有其他 year 值,请使用完整的四位数年份(例如 1520)。For all other year values, use the complete four-digit year (for example, 1520).


此示例使用 DateSerial 函数返回指定年月日的日期。This example uses the DateSerial function to return the date for the specified year, month, and day.

Dim MyDate
' MyDate contains the date for February 12, 1969.
MyDate = DateSerial(1969, 2, 12)    ' Return a date.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.