Crystal Reports Designer  

日期範圍 (Basic 和 Crystal 語法)

這些函式所產生的日期範圍是以目前的日期為準。例如,假如今天是 2000 年 9 月 18 日,那麼 LastFullMonth 就是日期範圍值:

CDate(#Aug 1, 2000#) To CDate(#Aug 31, 2000#)

這項功能很常用,但是如果想以資料庫欄位 (例如 {Orders.Order Date}) 為準來決定日期範圍的話又要如何?可以使用日期/時間函式來代替。

Basic 語法範例

Dim d As Date
d = CDate ({Orders.Order Date})
Dim dr As Date Range
dr = DateSerial (Year(d), Month(d) - 1, 1) To _
     DateSerial (Year(d), Month(d), 1 - 1)
'At this point dr is the Date Range value holding
'the last full month before {Orders.Order Date}

Crystal 語法範例

Local DateVar d := CDate ({Orders.Order Date});
Local DateVar Range dr;
dr := DateSerial (Year(d), Month(d) - 1, 1) To
      DateSerial (Year(d), Month(d), 1 - 1);
//At this point dr is the Date Range value holding
//the last full month before {Orders.Order Date}

使用 DateSerial 函式會更容易些,因為您不用擔心特殊情況,它根本不會讓您建立無效的日期。例如,DateSerial (1999, 1 - 1, 1) 就是 1998 年 12 月 1 日。在以上範例中,{Orders.Order Date} 事實上就是一個日期時間欄位,因此 CDate 函式是用來截取時間部分,以轉換成為日期。

請參閱

範圍資料型別 | 執行報表計算