Jump to content
Sign in to follow this  
fmsavey

Business days in a year

Recommended Posts

I'd like to be able to calculate the number of business days in a given year. Business days being Monday through Friday. Any help would be appreciated.

Share this post


Link to post
Share on other sites

Hi

try this CF

/*

BusinessDays ( theYear ; counter )

counter must be 1

( this CF works till year 4000 )

*/

Let([

start = Date ( 1 ; counter ; theYear );

end = Date ( 12 ; 31 ; theYear );

next = counter + 1;

value = DayOfWeek ( start ) > 1 and DayOfWeek ( start ) < 7

];

Case(

IsEmpty ( theYear ); "";

start < end ; value + BusinessDays ( theYear ; next );

value

)

)

Share this post


Link to post
Share on other sites

And if you don't have Advanced or don't want a Custom Function, you can use this, which works with any span between two dates:

If ( StartDate and EndDate ) ;

Let ( [

spanStart = StartDate - Mod ( StartDate ; 7 ) ;

spanEnd = EndDate - Mod ( EndDate ; 7 ) + 6 ;

wkndCount = Div ( spanEnd - spanStart + 1 ; 7 ) * 2 - (spanStart < StartDate ) - ( spanEnd > EndDate )

] ;

EndDate - StartDate + 1 - wkndCount

)

)

LaRetta :wink2:

Share this post


Link to post
Share on other sites

Hi LaRetta

beautiful calc !

Please, say me that it's not from your Brain...

I spended an hour to understand it ! :

Share this post


Link to post
Share on other sites

Yep, my calc, Danielle. It was a labor of love, sweat and blood and it can still be improved.

The span starts at the first Sunday prior to the start date and the span ends on Saturday after the end date. Weekend count is the full weeks in between then boolean test deducts one day if span starts before StartDate (indicating first day of span is Sunday and NOT within the range) and deducts one day if span ends after EndDate (indicating last day of span is Saturday and not within the range). Once we know the weekend count, we subtract weekend count from total days in the (inclusive) date range.

Again, there are actually more elegant ways - I've seen a few from the masters where they've taken far different approaches but they are not mine to share. Calculations, particularly date calculations, rock my world. :wink2:

LaRetta

Share this post


Link to post
Share on other sites

Again, there are actually more elegant ways - I've seen a few from the masters where they've taken far different approaches but they are not mine to share.

Why ?

Are calculations copyright protected ?

Share this post


Link to post
Share on other sites

If I remember a calc that someone else did, and I provide it, I always say who wrote the calc or point to the link But since I never can find the link (or where I stored the file), I usually don't refer to it at all. Copyright is not the issue ... respect is. If it is a simpler calc, I won't necessarily give credit because two different minds can easily come up with the same calculation. But when it is a significant achievement, I always give credit. What is a significant achievement? Those are grey areas only each person can answer. If I don't remember where I got the calc, I won't use it. If I can't remember the specific calc, I won't use it. That's why I write my own. Writing my own teaches me the principle behind it. When I get in bed with a concept, it sticks.

Awhile back I wrote a calc which I thought was an original. A few months later, I found an identical calc by someone else written prior to mine. While true that I created mine without assistance, I no longer considered it MY creation. There is also the obvious break of copyright - when the symbol is on somone's work. There are no questions in those instances.

Others may have different 'takes' on the subject but that's my perception. I don't want to copy anyone else. We can't help but copy the principles when we study the best but that isn't the same as copying. It's an internal indicator which should fire and your mind should tell you when you know you're pawning someone else's work as your own.

LaRetta

Share this post


Link to post
Share on other sites

My question was on this points:

1) more elegant ways

2) far different approaches

A calc with those "adjectives" must be seen and, if I see it once, I'll share it for sure, saying that it doesn't come from my brain.

So, for example, your calc can modify the CF, trashing the counter:

/*

BusinessDays ( theYear )

based on a LaRetta's calculation ( http://fmforums.com/forum/showtopic.php?tid/186908/ )

( this CF works till year 3999 )

*/

Let([

start = Date ( 1 ; 1 ; theYear ) ;

end = Date ( 12 ; 31 ; theYear ) ;

spanStart = start - Mod ( start ; 7 ) ;

spanEnd = end - Mod ( end ; 7 ) + 6 ;

wkndCount = Div ( spanEnd - spanStart + 1 ; 7 ) * 2 - (spanStart < start ) - ( spanEnd > end )

];

end - start + 1 - wkndCount

)

P.S.: we'll work 262 days next year and 2020 :

Share this post


Link to post
Share on other sites

I have no idea where you are trying to go with this.

No, I wouldn't include someone else's calculation in a custom function of mine (particularly without checking with them first) and no, you don't have my permission and no, it doesn't matter if you refer to its origin within your calculation.

No, I don't save everyone's calculations and mix and match and put them together in pieces ... I study principle pure and simple. I attack each problem anew to 1) find new ways of applying what I'm learning and 2) keep my mind sharp and the function concepts fresh. It is known as practice and nothing great happens without it.

No, not only is it wrong to include someone else's calculation within one of mine, but the other person may not want his calculation even repeated on a forum!! If I have knowledge to that effect, I have an obligation to respect that; which is exactly the case in one instance here. If those other people would have wanted their calculations posted, they can post them. It is one thing to refer to a post of someone else ... it is far another to take their calculation and put it inside one of yours or even to take it's guts (even if you strip it so it looks a bit different) and use it elsewhere. Theft is theft.

People have a right NOT to share ... people have a right NOT to provide the best that they know ... and people have an obligation to respect those rights in others; as well as to show respect for the accomplishments of others. People also have the right not to feel under inquisition when they simply provide a good calc in a post. Was what I provided not enough?

I'm not about to turn this into a copyright debate; I'm not good enough at that. I only know what my mind and heart says is right. And I believe, "If in doubt, leave it out." :

LaRetta

Edited by Guest

Share this post


Link to post
Share on other sites

Ahhh...

So your point is: this calc solves your problem but, because it's coming from my brain, you don't have my permission to use it.

Good to know.

P.S.: we are into "Custom Functions How To & Help" Forum

Share this post


Link to post
Share on other sites

Please do not twist my wording. You have permission to use my calc as presented ... as my calc and not melted into someone elses. Because I don't have the time to test your custom function to be sure it is worthy of my calc being a part of it - whereas I have thoroughly tested MY solution and know it works well. Just as with a demo file presented ... if someone tore it apart and changed it, I wouldn't allow my name on it as it was twisted.

Do you see the difference? I wonder if you understand the difference between something as an ORIGINAL and something changed and made into a copy.

Edited by Guest

Share this post


Link to post
Share on other sites

LaRetta, I didn't insert my name into that custom function, neither I'll do.

Share this post


Link to post
Share on other sites

I see you added clarity so I would know which forum we were in. Surpise. I knew it. What is your point? That if someone posts in Custom Function then only Custom Functions can be the response?

WRONG.

Many times people post here who don't need a custom function at all ... as in this case.

I'm not liking where this is going. I'm off to play with fun FileMaker things.

LaRetta

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.