Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginning of week

Status
Not open for further replies.

strom99

MIS
Nov 28, 2000
126
US
Hi

I have a field (BILL_RUN_DATE) which I need to group my report by. There are no weekend dates in this field, but I need to make sure that when grouped, the group header would say 03/19 or 03/26 to show that Monday was the beginning of the week. I tried the grouping option 'for each week' but the group headers came out with wrong dates. How do I define Monday as the first day of the week?

SCR version 8

Thanks
 
I've come across the problem before. The way I solved it was to use the "DayOfWeek" option... This returns a number for the day of the week (1 for Sunday, 2 for Monday, etc.)...

Now subtract the numbers of days away from your date (If Monday subtract 0, Tuesday, subtract 1, Weds subtract 2, etc.)

Combine this with an "if" statement, as follows:
Formula @StartOfWeek:

// Check to that the date is not a Sunday
If (DayOfWeek({Bill_Run_Date}) >= 2
// The Monday is BillRunDate - DayOfWeek - 2
then ({Bill_Run_Date} - (DayOfWeek({Bill_Run_Date}) - 2))
// else must be a Sunday - so add one day...
else ({Bill_Run_Date} + 1)

Okay, I should have used variables, but couldn't be bothered ;-)

Group the report by the new formula "@StartOfWeek".

Hope that helps, Chris
 
A simpler result would be to group on the original field each week, and delete the group name field (which will be a Sunday). In it's place on the group header put the following formula field:

{Bill_Run_Date} - DayOfWeek({Bill_Run_Date}) +2

This will print the Monday of each week. Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
Just wanted to let you know that the formula for week beginning is great and just what I needed.

Thanks,

Paula Park
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top