Day 函式 (Visual Basic)

更新:2007 年 11 月

傳回介於 1 到 31 間代表月份日期的 Integer 值。

Public Function Day(ByVal DateValue As DateTime) As Integer

參數

  • DateValue
    必要項。您希望抽出日數的 Date 值。

備註

如果使用 Day 函式,您可能必須利用 Microsoft.VisualBasic 命名空間 (Namespace) 來限定它,因為 System.Windows.Forms 命名空間會將 Day 定義為列舉型別 (Enumeration)。下列範例會顯示如何使 Day 有效解決這種模稜兩可 (Ambiguity) 的狀況:

Dim thisDay As Integer = Microsoft.VisualBasic.DateAndTime.Day(Now)

您也可以呼叫 DatePart 並指定 Interval 引數的 DateInterval.Day 取得月份中的日期。

範例

下列範例會使用 Day 函式,從指定日期取得月份的日數。在開發環境中會使用您程式碼中的地區設定,以標準簡短格式表示日期常值 (例如 "02/12/1969")。

Dim oldDate As Date
Dim oldDay As Integer
' Assign a date using standard short format.
oldDate = #2/12/1969#
oldDay = Microsoft.VisualBasic.DateAndTime.Day(oldDate)
' oldDay now contains 12.

Day 會加以限定,好與 System.Windows.Forms.Day 列舉型別有所區別。

需求

命名空間Microsoft.VisualBasic

**模組︰**DateAndTime

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

DatePart 函式 (Visual Basic)

Month 函式 (Visual Basic)

Now 屬性

Weekday 函式 (Visual Basic)

Year 函式 (Visual Basic)

DateTime

ArgumentException

ArgumentOutOfRangeException