DateSerial Function

Returns a Date value for a specified year, month, and day.

Syntax:


DateSerial(year, month, day)

Return value:

日期

Parameters:

Year:指示年份的整型表示式。0 到 99 之間的所有數值都會被解譯為 1900-1999 之間的年份。而對於此範圍之外的年份,必須輸入完整的四位數位。

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) 作為單獨的數值型表示式進行演算。

錯誤代碼:

5 無效的程序呼叫

Example:


  Sub ExampleDateSerial
  Dim lDate As Long
  Dim sDate As String
      lDate = DateSerial(1964, 4, 9)
      sDate = DateSerial(1964, 4, 9)
      msgbox lDate REM 傳回 23476
      MsgBox sDate ' returns 1964-04-09 in ISO 8601 format
  End Sub

Please support us!