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

date range assignment 1

Status
Not open for further replies.

leburg

Programmer
Feb 15, 2006
64
0
0
US
If I have 2 dates in mind and wish to use them to declare a date_range variable without the use of input parameters. How can I get it done in a formula?

9/1/2007
8/31/2008

TIA!
 
How do you want to use the date range? You can hard code the date range in a selection formula:

{table.date} in date(2007,9,1) to date(2008,8,31)

...or you can create conditional formulas like this:

if {table.date} in date(2007,9,1) to date(2008,8,31) then
{table.amt}

-LB
 
You can check dates on the basis of month and year. You can get to a past month from 'currentdate' by subtracting months using DateDiff. That way the range will depend just on the current month.

Get your 'end' month as
Code:
 ToText(Year((DateDiff("m", -2, currentdate))) & "/" & ToText(Month((DateDiff("m", -2, currentdate)))
The rest you should be able to figure for yourself.

It helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods sometimes change between versions, and higher versions have extra options.

If you don't have Year or Month as such, DatePart will do it.


[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
If you are running a monthly report and selecting the previous 12 months, then

{table.date} in [dateserial(year(currentdate),month(currentdate)-12,1) to maximum(lastfullmonth)]
 
I'm sorry I know better. Crystal Reports 8.5/MSserver2003

To say in other words, what I'm trying to accomplish...

I have 2 dates that I wish to use as a range so I want to assign the dates to a varible to use like a date range that you prompt for but never can see, as a whole, I am aware of how to max and mix the range and have the individual dates at your disposal. So, say I have 08/01/2007 and 07/31/2008 at hand, assign it to a formula as a range that later I can have a formula that test against it like:

formula: range= ? 08/01/2007 07/31/2008 (what I'm asking syntax for)
somewhere else...
if table.date = @range then true do something

I guess I could go with the min max less than greater than way I've bee doing.

Many thanks.
 
Create the following formula

//@DateRange
Shared DateVar Range dr := Date(2007,9,1) to Date(2008,8,31);

Then in your other formulas

shared DateVar Range dr;
if {table.date} in dr then
do this
else
do something else
 
Looks good but I keep coming up with a 'formula cannot result in a date range'. I tried it in both 8.5 and 11 with the same error message. This looks like its saying, it cannot be done'...

Thanks much for your time and effort.
 
The other alternative is to place the following formula in the report header.


//@RangeDate
shared datevar frDt := date(2007,9,1);
shared datevar toDt := date(2008,8,31);


Then in your formulas

//@otherFormula
shared datevar frDt;
shared datevar toDt;

if {table.date} in [frDt to toDt] then
Do this
else
Do that
 
All you need to do is add "" to the end of the first formula, as in:

//@DateRange
Shared DateVar Range dr := Date(2007,9,1) to Date(2008,8,31);
""

-LB
 
Hmmmm.... Wasn't aware of that.

A star for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top