Print Page | Close Window

Which days are work days in a given range

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=13568
Printed Date: 05 May 2024 at 11:08pm


Topic: Which days are work days in a given range
Posted By: zach18
Subject: Which days are work days in a given range
Date Posted: 22 Jun 2011 at 4:38am
Is there a built in function that will tell me which days are work days? this is what i mean,

If I were to choose today's date (6/14/2011), it will give me any inspection numbers clocked out today. This lead time includes weekends. So if I had a customer start a project on the 10th (Friday) and finish it today; it would show it took about five days, instead of three.

-------------
Using Crystal Report 2008
www.zachtech.us



Replies:
Posted By: kostya1122
Date Posted: 22 Jun 2011 at 5:04am
you could try dayofweek function, with it help you could exclude (sat,sun) from your results  (Sun = 1, Sat = 7)


Posted By: zach18
Date Posted: 23 Jun 2011 at 7:23am
here is my solution

if({@timeDiff} >= 35) then
{@timeDiff} - 10
else if({@timeDiff} >= 28) then
{@timeDiff} - 8
else if({@timeDiff} >= 21) then
{@timeDiff} - 6
else if({@timeDiff} >= 14) then
{@timeDiff} - 4
else if({@timeDiff} >= 7) then
{@timeDiff} - 2
else if(DayOfWeek({Command.DateTimeStamp}) < DayOfWeek({Command.CreatedDate})) then
{@timeDiff} - 2
else
{@timeDiff}

for an explanation go here to by website to read up on it.
http://www.zachtech.us/blog/2011/06/23/how-to-determine-if-weekends-are-selected-in-date-range/#more-72 - explanation

-------------
Using Crystal Report 2008
www.zachtech.us


Posted By: Keikoku
Date Posted: 23 Jun 2011 at 9:42am
What if a client spent 60 days on a project?
It wouldn't be 10 days worth of weekends.

Also, here is a trickier case:

Suppose I started working on wednesday 8th and finished on monday 27th.

Thus, without deducting any weekends, I have apparently spent 20 days on the project.

2 weekends have definitely passed (so Wed 22nd would be the start of my third week) but then in the remaining 6 days, I happened to run into another weekend.

This would probably need to be considered as well.

I also thought about this problem for some time at one point: http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=13368&KW= - http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=13368&KW=


Posted By: zach18
Date Posted: 23 Jun 2011 at 9:50am
well then the numbers will be off, this solution worked for the extent of my project. that solution isnt the best and as you pointed out has a flaw. how would you go about fixing it? other than making a lot more if statements

-------------
Using Crystal Report 2008
www.zachtech.us


Posted By: Keikoku
Date Posted: 23 Jun 2011 at 9:53am
Basically, the total number of weeks that have passed and the remaining days should be calculated separately.

But it will only be off by a maximum of 2 days so if you do not need such accuracy (ie: auditing) then it doesn't matter.


Posted By: zach18
Date Posted: 23 Jun 2011 at 9:53am
this is a much better solution

-------------
Using Crystal Report 2008
www.zachtech.us



Print Page | Close Window