# Count the number of Mondays (or specified weekday) in a date range?

**URL:** <https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768>\
**Category:** Get Help\
**Created:** [January 29, 2024, 4:52pm UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768 "2024-01-29T16:52:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Claire\_RM](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/claire_rm/32/8724_2.png) [@Claire\_RM](https://community.fibery.io/u/Claire_RM)\
**Post date:** [January 29, 2024, 4:52pm UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768/1 "2024-01-29T16:52:42Z")

</div>

I’m entering term dates / a time period (using the Date field with Start + End dates specified).  
I’d like it to calculate how many Mondays occur during that time period (inclusive of the start and end dates).  
And then I’d repeat the formula for other days so that I’d end up with 5 formulas to cover each weekday.  
Separately I’ve used a basic formula to display how many weeks happen between the dates (total days / 7!) and have displayed in different fields the day of the week the period starts on, and ends on. This helps the user manually work out how many of which weekday occur, but I was hoping there was a formula to do the maths for us!  
Ideas in simple language would be much appreciated 😉

IF I can get it to display how many Mondays in a given date range, I’d further like it to calculate something like this:  
Where Student is booked onto a session that occurs on a Monday, auto display how many sessions they’re booked on to UNLESS their “Individual Start Date” occurs later than the “Actual Term Start Date” in which case reduce the number of Mondays using their “Individual Start Date” (or do something else like flag this field…?!).

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 7, 2024, 4:17pm UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768/2 "2024-02-07T16:17:34Z")

</div>

You probably need to utilise something like this

```auto
If(WeekDayName(Date.Start()) = "Monday",0,
If(WeekDayName(Date.Start()) = "Tuesday",1,
If(WeekDayName(Date.Start()) = "Wednesday",2,
If(WeekDayName(Date.Start()) = "Thursday",3,
If(WeekDayName(Date.Start()) = "Friday",4,
If(WeekDayName(Date.Start()) = "Saturday",5,
6))))))

```

to take into account which day of the week the time period starts on, and then calculate the number of whole/partial weeks in the time from start to end.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 12, 2024, 11:45am UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768/3 "2024-02-12T11:45:51Z")

</div>

To provide a concrete answer for how to calculate the number of Mondays in a given date range, I would suggest the following:

- use the above in a formula field called `Weekday` that returns a number between 0 and 6
- use further formulas as follows:

Monday count:

```auto
RoundDown(
  (ToDays(Term.End(false) - Term.Start()) +
    If(Weekday - 1 < 0, Weekday + 6, Weekday - 1)) /
    7,
  0
)

```

Tuesday count

```auto
RoundDown(
  (ToDays(Term.End(false) - Term.Start()) +
    If(Weekday - 2 < 0, Weekday + 5, Weekday - 2)) /
    7,
  0
)

```

and so on.

Note: There are other ways of solving this problem, for example, by creating a db of Dates, and using automation to link each entity to a collection of Dates, based on the start and end dates, and then using formulas like `Dates.Filter(WeekDayName(Date) = "Monday).Count()`

Ideally, in the future we will improve the handling of dates/time periods to make issues like this easier to solve.

---

<div class="post-metadata">

**Author:** ![Claire\_RM](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/claire_rm/32/8724_2.png) [@Claire\_RM](https://community.fibery.io/u/Claire_RM)\
**Post date:** [February 12, 2024, 12:47pm UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768/4 "2024-02-12T12:47:55Z")

</div>

Thank you, that’s worked! Appreciate that. This means I don’t have to look into paying for a Dates API etc.  
(It does mean quite a few extra fields for my intended end user that I don’t want them to touch but I think this is a workable solution.)

---

<div class="post-metadata">

**Author:** ![mdubakov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/mdubakov/32/10_2.png) [@mdubakov](https://community.fibery.io/u/mdubakov)\
**Post date:** [December 5, 2024, 6:51pm UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768/5 "2024-12-05T18:51:24Z")

</div>

Weekday(Date) function was added in last release

> [@December 5, 2024 / snowflake Sync several email accounts into the same database, new Sticky notes, LaTeX in rich text](https://community.fibery.io/t/december-5-2024-sync-several-email-accounts-into-the-same-database-new-sticky-notes-latex-in-rich-text/7899):
>
> First winter release with some unexpected features is here. broccoli Sync several email accounts into the same database Now you can sync several personal email accounts into the same database. For example, for CRM use case you have 3 sales reps that communicate with customers and want to sync all their emails into a single Emails database. Check the [detailed user guide how to enable multiple emails accounts](https://the.fibery.io/@public/User_Guide/Guide/Multiple-Email-Accounts-Sync-381). Setup new Email Sync and enable Allow users to add personal integrations option.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [December 10, 2024, 11:48am UTC](https://community.fibery.io/t/count-the-number-of-mondays-or-specified-weekday-in-a-date-range/5768/6 "2024-12-10T11:48:15Z")

</div>

Note, [the new `Weekday()` function](https://community.fibery.io/t/december-5-2024-sync-several-email-accounts-into-the-same-database-new-sticky-notes-latex-in-rich-text/7899) will simplify some of the above formulas
