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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal hard coded previous Sunday starting date 1

Status
Not open for further replies.

GCL2007

IS-IT--Management
Dec 11, 2007
167
US
I have a Crystal report with a parameter for Starting date. The report then uses that starting date to create weekly buckets for reporting (?StartingDate+7,?StartingDate+14,etc). I need to remove the selection criteria so we can run the report in batch mode. I want to set the starting date variable to always be the previous Sunday date from the date it is run. Any idea how I can do that automatically in a formula?
 
This feels klunky but i think would work.

{@StartonSunday}
datevar sd;

IF dayofweek(currentdate)=1
then sd := currentdate
else
(
IF dayofweek(currentdate)=2
then sd := currentdate-1
else
(
IF dayofweek(currentdate)=3
then sd := currentdate-2
else
(
IF dayofweek(currentdate)=4
then sd := currentdate-3
else
(
IF dayofweek(currentdate)=5
then sd := currentdate-4
else
(
IF dayofweek(currentdate)=6
then sd := currentdate-5
else
(
IF dayofweek(currentdate)=7
then sd := currentdate-6
))))));
sd



a second option would be to use CASE something like this:
{@StartonSundayCASE}
select (dayofweek(curentdate))
CASE 1:
currentdate
CASE 2:
currentdate-1
CASE 3:
currentdate-2
CASE 4:
currentdate-3
CASE 5:
currentdate-4
CASE 6:
currentdate-5
CASE 7:
currentdate-6
 
{table.date} >= currentdate-dayofweek(currentdate)+1

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top