INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Formula Help

How to select X number of months based on 1 parm date by bkrav
Posted: 30 Aug 06 (Edited 30 Aug 06)

Hi!

This code (done in Crystal 10) will select records based on a parameter (?date) for the last X number of dates (which can also be a parameter, or simply hardcoded like in the example).  This code is useful when you only want one date entered as a parameter, as it could easily be accomplished with two date parameters.  Enjoy!

//number of months to look back (CANNOT BE ZERO) must be 1-12
local numbervar months_back := 3;

local numbervar month_start:= iif(month({?date})<months_back, month({?date})+(13-months_back),month({?date})-(months_back-1));
local numbervar date_start:= 1;
local numbervar year_start:= iif(month({?date})<months_back, year({?date})-1,year({?date}));

//first day of month, X months ago
local datevar date_begin := DateValue (year_start, month_start, date_start);

//end date + X months - 1 day (to capture last day of month)
local datetimevar date_end := DateAdd("d",-1,DateAdd ("m",months_back,date_begin ));

//dates between start and end date
{Table.Date_Field} in (date_begin to date_end)

Back to Business Objects: Crystal Reports 1 Formulas FAQ Index
Back to Business Objects: Crystal Reports 1 Formulas Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close