Crystal Reports Designer  

日期范围(Basic 和 Crystal 语法)

这些函数产生的日期范围取决于当前日期。例如,如果今天的日期是 2000 年 9 月 18 日,那么 LastFullMonth 就是“日期范围”值:

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

该功能通常很有用,但如果想根据数据库字段(如 {订单.订单日期})确定日期范围,可以改用日期/时间函数。

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 日。注意,在上例中,{订单.订单日期} 实际上是“日期时间”字段,因此使用了 CDate 函数截断它的时间部分以将其转换为日期。

另请参见

范围数据类型 | 执行报表计算