共用方式為


計算並顯示特定的日期值

因為日期值是以雙精準數儲存,所以如果嘗試在運算式中操作日期值,可能就會收到不正確的格式。 本主題說明如何建立顯示特定日期與計算時間區間的運算式及自訂函數。

當月

DateSerial(Year(Date()), Month(Date()), 1)

下個月

DateSerial(Year(Date()), Month(Date()) + 1, 1)

當月的最後一天

DateSerial(Year(Date()), Month(Date()) + 1, 0)

下個月的最後一天

DateSerial(Year(Date()), Month(Date()) + 2, 0)

上個月的第一天

DateSerial(Year(Date()), Month(Date())-1,1)

上個月的最後一天

DateSerial(Year(Date()), Month(Date()),0)

當季的第一天

DateSerial(Year(Date()), Int((Month(Date()) - 1) / 3) * 3 + 1, 1)

當季的最後一天

DateSerial(Year(Date()), Int((Month(Date()) - 1) / 3) * 3 + 4, 0)

假設星期日 = 第 1 天 (目前星期的第一天)

Date() - WeekDay(Date()) + 1

當周的最後一天

Date() - WeekDay(Date()) + 7

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應