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

Days in a Period Grouped by Month 1

Status
Not open for further replies.

galleyne

MIS
Sep 5, 2002
6
0
0
BB
Hi

I am using CR 8.5. I have a start date and an end date and I need to caluculate the number days between them and display the relevant number of days under the correct month. For example, if the start date is Jan 5 2003 and the end date is Mar 3 2003 and need to show 27 days in jan, 28 days feb, and 3 in mar. Any ideas?

Thanks in advance
 
Here's a formula:

stringvar firstmon;
stringvar months;
numbervar counter;
numbervar i := datediff("m",{?start},{?end});

firstmon := firstmon + (if {?end} >=
dateadd("m",1,{?start}-day({?start})+1) then
monthname(month({?start})) + " - "+
totext(datediff("d",{?start},dateadd("m",1,{?start}-
day({?start}))+1),0,"") +chr(13) else
if {?end} < dateadd("m",1,{?start}-day({?start})+1) then
monthname(month({?start})) + " - "+
totext(datediff("d",{?start},{?end}),0,"") +chr(13));

for counter := 1 to i do(
months := months + if dateadd("m",counter,{?start}) <= dateserial(year({?end}),month({?end})+counter,01)-1 then
monthname(month(dateadd("m",counter,{?start}))) + " - "+
(if {?end} <= dateserial(year({?start}),month({?start})+counter+1,01)-1 then
totext(datediff("d",dateserial(year({?start}),month({?start})+counter,01),{?end})+1,0,"") else
if {?end} >= dateserial(year({?start}),month({?start})+counter+1,01)-1 then
totext((datediff("d",dateserial(year({?start}),month({?start})+counter,01),dateserial(year({?start}),month({?start})+counter+1,01))),0,"") +chr(13)));
firstmon + months;

This will result in a display like the following for {?start} = 11/5/2003 and {?end} = 1/6/2004:

November - 5
December - 31
Jan - 6

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top