Date ranges produced by these functions depend on the current date. For example, if today's date is September 18, 2000, then LastFullMonth is the Date Range value:
CDate(#Aug 1, 2000#) To CDate(#Aug 31, 2000#)
This functionality is often useful, but if you want to determine a date range based on a database field such as {Orders.Order Date}? The Date/Time functions can be used instead.
Basic Syntax Example
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 Syntax Example
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}
The DateSerial function makes this easy because you don't have to worry about special cases. It never lets you create an invalid date. For example, DateSerial (1999, 1 - 1, 1) is December 1, 1998. Note that in the above example, {Orders.Order Date} is actually a DateTime field and so the CDate function is used to convert it to a date by truncating the time part.