Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Counting Certain Days in a Range Post Reply Post New Topic
Author Message
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Topic: Counting Certain Days in a Range
    Posted: 08 Dec 2010 at 6:04am
I have a date range parameter {?Login Date} and I need to see how many Saturdays and Sundays fall within that date range. Anyway of doing so?
 
Any help is appreciated.
|< /\ '][' ( )
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 08 Dec 2010 at 7:31am
I tell ya, I can make some pretty ugly formulas....But they work so I'm happy!!!
 
Here's what I came up with:
 
local numbervar nSatorSun:=nSatorSun + (if 2<={@Days in Date Range}
    then (if weekdayname(dayofweek(dateadd('d',+1,{@DateRangeMin})))='Saturday'
or weekdayname(dayofweek(dateadd('d',+1,{@DateRangeMin})))='Sunday'
    then 1
        else 0)
            else 0);
Then do one incrementing compare number to Days in Date Range and the dateadd number by 1 until 31 days are represented (the report will only be run for a maximum of 1 month).
 
Days in Date Range=datediff('d',DateRangeMin, DateRangeMax)+1
 
It's ugly, but like I said, it works and gives me the conunt of Saturdays and Sundays.
 
PLEASE!!!!! If anyone else has an easier way, clue me in on it.
 
Thanks.
 
|< /\ '][' ( )
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 08 Dec 2010 at 8:58am
We know that in 7 days, there is exactly one sat and one sun.

We then only have to iterate the remaining days and check whether they're saturday or sunday.

It won't make your code any cleaner, but it will save you from having to loop so many times.

Edited by Keikoku - 08 Dec 2010 at 9:38am
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.