LibreOffice 25.2 帮助
Returns a Date value for a specified year, month, and day.
DateSerial (year, month, day)
日期
「Year」: 整数表达式,表示年份。1900-1999 之间的年份可以用 0 到 99 之间相应的数值表示,而对于超出此范围的年份,必须输入完整的四位数字。
「Month」: 整数表达式,表示指定年份中的月份。有效值范围是 1-12。
「Day」: 整数表达式,表示指定月份中的日期。有效值域为 1-31。针对不满 31 天的月份,输入不存在的日期不会返回任何错误。
「DateSerial 函数」返回 1899 年 12 月 30 日与给定日期之间相差的天数。因此,可以使用此函数计算两个日期之间相差的天数。
The DateSerial function returns the data type Variant with VarType 7 (Date). Internally, this value is stored as a Double value, so that when the given date is 1900-01-01, the returned value is 2. Negative values correspond to dates before December 30, 1899 (not inclusive).
如果定义的日期超出了有效值范围,LibreOffice Basic 将返回一个错误报告。
由于「DateValue 函数」中可以定义含有日期的字符串,因此「DateSerial 函数」将每个参数 (year、month、day) 当作独立的数字表达式来求值。
Sub ExampleDateSerial
Dim lDate As Long
Dim sDate As String
lDate = DateSerial(1964, 4, 9)
sDate = DateSerial(1964, 4, 9)
MsgBox lDate ' 返回 23476
MsgBox sDate ' returns 1964-04-09 in ISO 8601 format
End Sub