Print Page | Close Window

Date Parameters

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17171
Printed Date: 02 May 2024 at 7:35pm


Topic: Date Parameters
Posted By: Abhi
Subject: Date Parameters
Date Posted: 31 Jul 2012 at 10:18am
Hi All-

My Report is a table based and the parameters used to run the report are start and end date.

The Start date has below values
Yesterday
First day of Previous week
First day of Previous month
First day of Previous quarter
First day of Previous 12 Months
First day of Previous 6 Months

End Date Has below values
Today
Last day of Previous week
Last day of Previous month
Last day of Previous quarter

The user runs by selecting any of the values from start date and end date based these values ranges the report should get the orders created.

Please advise

Thanks!
Abhi





Replies:
Posted By: Sastry
Date Posted: 31 Jul 2012 at 12:44pm
Hi
 
Create to static string parameters and give the same values as default values.
 
Create a Formula with the following to get StartDate Value and compare it with your database field in record selection.
 
Note : I am giving only for Start Date, you will have to write for End date.
 
Datevar StDate;
If {?StartDate} = 'Yesterday' then StDate: = Currentdate -1 
else
If {?StartDate} = 'First Day of Previous Week' then
    StDate: = dateadd('ww',-1,currentdate)-(weekday(currentdate)-2)
else
If {?StartDate} = 'First Day of Previous Month' then
    StDate: = dateadd('m',-1,currentdate)-day(currentdate)+1
else
If {?StartDate} = 'First Day of Previous Quarter' then
    StDate: =( if Month(currentdate) in [1,2,3] then date(year(currentdate)-1,10,1)
else
if Month(currentdate) in [4,5,6] then date(year(currentdate),01,01)
else
if Month(currentdate) in [7,8,9] then date(year(currentdate),04,01)
else
if Month(currentdate) in [10,11,12] then date(year(currentdate),07,01)
)
else
if {?StartDate} = 'First Day of Previous 12 Months' then
StDate: = date(year(dateadd('y',-1,currentdate)),month(currentdate),01)
else
if {?StartDate} = 'First Day of Previous 6 Months' then 
StDate:=date(year(dateadd('m',-6,currentdate)),Month(dateadd('m',-6,currentdate)),01)
StDate;
 
 


-------------
Thanks,
Sastry


Posted By: Abhi
Date Posted: 01 Aug 2012 at 5:05pm
Hi Sastry

Thank You for your prompt response..
but I get an error saying date is required at the line dateadd('ww',-1,currentdate)-(weekday(currentdate)-2).

thks
Abhi


Posted By: Sastry
Date Posted: 02 Aug 2012 at 1:30pm
Hi
Initialize the variable with datetimevar
 
i.e.
 
datetimevar Stdate;


-------------
Thanks,
Sastry


Posted By: Abhi
Date Posted: 02 Aug 2012 at 5:20pm
Well ..I used the date conversion and it worked out for me..

Again.. Thanks very much for your help..
Thks
ABHI



Print Page | Close Window