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

While loop 1

Status
Not open for further replies.

mikkom

Technical User
Jul 23, 2010
29
FI
In database there are date and period in weeks. I know that I can count next date with dateadd function:
dateadd("ww", {@period}, {@date})

But I need to add so many periods that result is bigger or equal than today. I think I need while loop?

 
It's not clear what you're trying to do. Possible DatePart would help. Or grouping by date, which can include a choice of period.

This is based on Crystal 11. It always 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.



[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
I try to add period in weeks to beginning date so many times that end date is same or bigger today. How I can do while loop for that?
 
DateDiff will give you the difference in days, weeks or whatever. It can be positive or negative, use that for future dates.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
PS. You can't actually 'loop' in Crystal, which is a report-writing tool rather than a full language.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
I have start date for maintenance work, for example 2/21/2000 and period in weeks, eg. 104. When I add period to start date once I get date 2/18/2002.

But I need to know when this work is coming next time in future. In other words, I have to add period to start date so many times that result date is in future. How I can do that with crystal?
 
Try:

datevar nextdt := {table.startdate};
numbervar i := 104;
while nextdt <= currentdate + i do (
nextdt := dateadd("d",i,nextdt)
);
nextdt

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top