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!

Hi! I have a problem extracting

Status
Not open for further replies.

theamis

MIS
Jul 9, 2002
15
PH
Hi!

I have a problem extracting the right data where the date range will be the last year previous month of the current month.

Example 1:
My date is: 2/10/2003
I want to get all the data from 1/1/2002 to 1/31/2002 and not LastYearMTD.
Example 2:
My date is : 12/31/2002
I want to see all the data from 11/1/2001 to 11/30/2001.

By the way, I am using Crystal Report v7
Thanks for the help
 
Hello !

One way is to use the DateAdd function that came with version 8, but wich can be downloaded from
Then you can create two formulas
@Firstdate
DateTime(year(dateadd("m",-13,currentdate)),month(dateadd("m",-13,currentdate)),1,0,0,0)

@Lastdate
DateTime(year(dateadd("m",-12,currentdate)),month(dateadd("m",-12,currentdate)),1,23,59,59)-1

Then in your Record Selection Criteria you write:
{Table.YourDate} >= @Firstdate and
{Table.YourDate} <= @Lastdate


This will pass the SQL to the database.

/Goran
 
I try the formula that you had given but it generate an error: &quot;A Date time is required here.&quot;

I always have a problem regarding the DateAdd function. Is there an alternative way to do this?

Thanks
 
Hi !

You can try to use Date instead of DateTime, like this:

@Firstdate
Date(year(dateadd(&quot;m&quot;,-13,currentdate)),month(dateadd(&quot;m&quot;,-13,currentdate)),1)

@Lastdate
Date(year(dateadd(&quot;m&quot;,-12,currentdate)),month(dateadd(&quot;m&quot;,-12,currentdate)),1)-1

/Goran
 
Hi again !

Another way without using the DateAdd function at all:

@Firstdate
if month(currentdate) = 1 then
Date(year(currentdate)-2,12,1)
else
Date(year(currentdate)-1,month(currentdate)-1,1)

@Lastdate
if month(currentdate) = 1 then
Date(year(currentdate)-2,12,31)
else
Date(year(currentdate)-1,month(currentdate),1)-1


/Goran
 
Hello!

Thank you very much for the replies. I'll definitely try it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top