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!

Current year vs. Previous year data (Designating year)

Status
Not open for further replies.

dhgrrg

IS-IT--Management
Jun 16, 2004
14
US
I'm pulling information for the in the Select Section for current month based on the formula below:

Month ({v_bss_GDI_Attendance_B.DateStamp}) = Month (CurrentDate)

This works well until I have gone 1 full year and I have two January's then I will have two entries for January (one 2004 and one 2005). My questions are as follows:

How do I limit information pulled to this year only?

If I use a current year statement and in "January 2005" want to use a subreport to pick up previous month "December 2004", how do I tell it current year for January and previous year for December?

I'm sure the answer is straight forward.

thanks in advance
 
I use Crystal 8.5 and I use dateserial function often

Code:
{table.date} in dateserial(year(currentdate),month(currentdate)-2,1) to_ dateserial(year(currentdate),month(currentdate),1)

Translated, this will evaluate to

{table.date} => 12/1/2004 and
{table.date} < 2/1/2005

Cheers,

-LW
 
You can also use the some of the buil in date range functions:

LastFullMonth
MonthtoDate

//returns any dates that fall between the first and last day of the last calendar month
{table.date} in lastfullmonth

//returns any dates that fall between the first and current day of the current calendar month
{table.date} in monthtodate

You can also use these with the minimum and maximum functions to return custom ranges:

//returns any dates that fall between the first day of the last calendar month and today
{table.date} in minimum(lastfullmonth) to maximum(monthtodate)

~Brian
 
Modifying kskid's example slightly:

{table.date} in dateserial(year(currentdate),month(currentdate)-1,1) to dateserial(year(currentdate),month(currentdate)+1,1)-1

Note the change of month(currentdate)-2 to month(currentdate)-1 to go back just one month, and in the dateserial(year(currentdate),month(currentdate),1), I add a month and then subtract a day so that it returns the last day of the current month.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top