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

Formula to display dates on 6 month cycle

Status
Not open for further replies.

Robb2009

Technical User
Dec 3, 2009
3
US
Hello,
Here is my setup Crystal Reports 9 running against SQL Server Database. Based on the field {OPENCLOSE.GENERICDATE1} I need to display a target date every 6 months for at least the next 5 years.

I am able to do one 6 month interval with the following formula

DateAdd ("m", 6, {OPENCLOSE.GENERICDATE1})

Is there a way to loop this for the next 5 years. Also {OPENCLOSE.GENERICDATE1} could be several years in the past, but I only need future dates from CurrentDate. How do I eliminate dates in the past?

I appreciate any suggestions. Thanks.
 
Create a formula like the following:

numbervar cnt;
numbervar j := 10;
stringvar x := "";
for cnt := 1 to j do(
if {table.date} >= currentdate then
x := x + totext(dateadd("m",cnt*6,{table.date}),"MM/dd/yyyy")+ chr(13)
);
x

Format the formula to "can grow". This, however, places all dates in one field--not sure this is what you are looking for.

-LB
 
Hi LB,
Thanks for the formula. There is only one problem and I may not have stated this clearly in my original post {table.date} will always be <= currentdate. So what I need are only the outputs that are >= currentdate if that makes sense. So For example:

If {table.date} is 12/4/2007 and currentdate is 12/4/2009 I don't need to know that there were 3 six month intervals in the last two years. I only need to know about the dates in the future from currentdate.

Thanks,
Robb
 
numbervar cnt;
numbervar j := 10;
stringvar x := "";
for cnt := 1 to j do(
if dateadd("m",cnt*6,{table.date}) >= currentdate then
x := x + totext(dateadd("m",cnt*6,{table.date}),"MM/dd/yyyy")+ chr(13));
x

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top