I have a table in my oracle database, with the following schema: student(studentNumber,name, dateOfCreation).
dateOfCreation is the date in which the student record was created.
In crystal reports, I have to group the records into the following groups, using the dateOfCreation field:
Older than 4 weeks(Records whose dateOfCreation is more than 4 weeks ago).
Between 2 and 4 weeks (Records whose dateOfCreation is more than 2 weeks ago, but less than 4 weeks ago).
Between 1 and 2 weeks(Records whose dateOfCreation is more than 1 week ago, but less than 2 weeks ago).
Less than 1 week (Records whose dateOfCreation is less than 1 week ago).
I have tried grouping in specified order using group expert, but I just can't find these groups. Please help out. How do I achieve this?
Create a formula to group on.
The formula qould read something like (in pseudo code):
if CreationDate > 4 weeks
then A;
else if CreationDate >2 weeks and CreationDate <4 weeks
then B;
You can then create a group on this formula.
CR has adequate date functions in order to find the date difference between creation and the current date.
As @vice suggested, create a formula and then group on it - a formula like this should work:
if DateDiff ("d", {student.dateOfCreation}, CurrentDate) > 28 then 1
else if DateDiff ("d", {student.dateOfCreation}, CurrentDate) > 14 and
DateDiff ("d", {student.dateOfCreation}, CurrentDate) < 28 then 2
else if DateDiff ("d", {student.dateOfCreation}, CurrentDate) > 7 and
DateDiff ("d", {student.dateOfCreation}, CurrentDate) < 14 then 3
else if DateDiff ("d", {student.dateOfCreation}, CurrentDate) < 7 then 4
( {student.dateOfCreation}
may need to be amended to match Crystal's representation of this field - you should be able to find this in the Field Tree pane in the Formula Editor.)
Note that this formula matches the conditions in your questions exactly - it therefore does not allow for dateOfCreation values that are exactly 1, 2 or 4 weeks old. I suggest you adjust it to take these into account.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.