# \[DONE\] Week number formulas

**URL:** https://community.fibery.io/t/done-week-number-formulas/3880
**Category:** Fibery Showcase
**Tags:** formulas
**Created:** [January 30, 2023, 5:12pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880 "2023-01-30T17:12:25Z")
**Posts on this page:** 12
**Page:** 1

<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: [January 30, 2023, 5:12pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/1 "2023-01-30T17:12:25Z")

</div>

**UPDATE** : improved formulas [below](https://community.fibery.io/t/week-number-formulas/3880/6).  
**UPDATE 2** : native week number function is now [available](https://community.fibery.io/t/january-9-2025-set-any-relative-value-in-date-filter-batch-change-fields-for-selected-entities-improved-readability-in-rich-text-fields-some-new-formulas/8082#p-30013-isoweeknumdate-calculate-the-week-number-in-formulas-6).

After a couple of people asked about calculating week numbers for a given date, I thought I’d share these two formulas that you might find useful:

WeekYear:

```auto
Year(DateField + Days(
If(WeekDayName(DateField) = "Monday",3,
If(WeekDayName(DateField) = "Tuesday",2,
If(WeekDayName(DateField) = "Wednesday",1,
If(WeekDayName(DateField) = "Thursday",0,
If(WeekDayName(DateField) = "Friday",-1,
If(WeekDayName(DateField) = "Saturday",-2,
-3))))))))

```

The above formula tells you which year a given date is in 🤔

This might sound crazy, but 1st Jan 2023 is actually in the year 2022 as far as week numbers are concerned (it’s week 52) and 31st Dec 2024 is actually in the year 2025 (week 1) 🤪  
It is the Thursday in any given week that determines which year that week falls under.

Then, this formula can be used as follows to work out the week number:

```auto
RoundUp(ToDays(DateField - 
(Date(WeekYear,1,1) + Days(
If(WeekDayName(Date(WeekYear,1,4)) = "Monday",2,
If(WeekDayName(Date(WeekYear,1,4)) = "Tuesday",1,
If(WeekDayName(Date(WeekYear,1,4)) = "Wednesday",0,
If(WeekDayName(Date(WeekYear,1,4)) = "Thursday",-1,
If(WeekDayName(Date(WeekYear,1,4)) = "Friday",-2,
If(WeekDayName(Date(WeekYear,1,4)) = "Saturday",-3,
-4))))))))) / 7,0)

```

This works by determining the last day of the previous year (using the rule that the 4th January is always in week 1) and calculating how many weeks (incl fractions of a week) have elapsed since then.

Hope this is useful.

---

<div class="post-metadata">

### Author: ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)
#### Post date: [January 1, 2024, 10:18pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/2 "2024-01-01T22:18:12Z")

</div>

Hey @Chr1sG,

These formulas are great for getting the week year/week number from a date, but is there a equivalent you could help create that would essentially do the opposite, which is to get a specific date from a week number/week year/day of the week?

For example, if I had the week year (2024) and week number (2) defined and wanted to find the actual date of the Monday of that week, the result would be something like 01-08-2024 (MM-DD-YYYY)?

---

<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: [January 2, 2024, 8:53am UTC](https://community.fibery.io/t/done-week-number-formulas/3880/3 "2024-01-02T08:53:12Z")

</div>

```auto
Date(Year, 1, 1) -
  Days(
    If(WeekDayName(Date(Year, 1, 1)) = "Monday", 7,
    If(WeekDayName(Date(Year, 1, 1)) = "Tuesday", 8,
    If(WeekDayName(Date(Year, 1, 1)) = "Wednesday", 9,
    If(WeekDayName(Date(Year, 1, 1)) = "Thursday", 10,
    If(WeekDayName(Date(Year, 1, 1)) = "Friday", 4,
    If(WeekDayName(Date(Year, 1, 1)) = "Saturday", 5, 6))))))
  ) +
  Days(Week * 7)

```

This gets you the Monday for a given `Year` and `Week`

(it has no error checking, so invalid year or week numbers will give odd results)

If you need a different day of the week, you could add something like this

```auto
+ Days(DayOfTheWeek -1)

```

where DayOfTheWeek is a number between 1 and 7 to represent Monday to Sunday.

---

<div class="post-metadata">

### Author: ![bear](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/bear/32/12872_2.png) [@bear](https://community.fibery.io/u/bear)
#### Post date: [January 2, 2024, 2:47pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/4 "2024-01-02T14:47:58Z")

</div>

Thanks for sharing, I can see how that will be useful for me in the future.

Also interesting to hear how week numbers work.

---

<div class="post-metadata">

### Author: ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)
#### Post date: [January 3, 2024, 2:26am UTC](https://community.fibery.io/t/done-week-number-formulas/3880/5 "2024-01-03T02:26:57Z")

</div>

Thank you!

---

<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, 1:45pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/6 "2024-12-10T13:45:28Z")

</div>

The formulas can now be simplified as follows:

WeekYear:  
`Year(DateField + Days(4 - Weekday(DateField)))`

WeekNum:

```auto
RoundUp(
  ToDays(
    DateField - (Date(WeekYear, 1, 1) + Days(3 - Weekday(Date(WeekYear, 1, 4))))
  ) / 7,
  0
)

```

---

<div class="post-metadata">

### Author: ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)
#### Post date: [January 2, 2025, 11:33pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/7 "2025-01-02T23:33:22Z")

</div>

A bunch of things broke for us over the new years holiday because the formula was spitting out that Dec 30 and Dec 31 were in week 53, instead of week 1!

@Chr1sG, is there a more reliable week number formula you could help craft that spits out a value that is compliant with the [ISO-8601](https://www.epochconverter.com/weeknumbers)?

They define the first week of the year as the one that contains the first Thursday, or in other words, the first week that has at least 4 days in the year.

and is there a dedicated “WeekNum” function on the horizon that will negate the need for these complex formulas all together?

---

<div class="post-metadata">

### Author: ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)
#### Post date: [January 2, 2025, 11:49pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/8 "2025-01-02T23:49:28Z")

</div>

Actually, I see the error in our ways. We were using the week num formula you have, but just setting the week year as the exact calendar year instead of formatting it like yours.

So it all works as expected, was just hoping to not use 2 formulas. Guess we would create one mega formula if we wanted, right?

```auto
RoundUp(
  ToDays(
    DateField - (Date(Year(DateField + Days(4 - Weekday(DateField))), 1, 1) + Days(3 - Weekday(Date(Year(DateField + Days(4 - Weekday(DateField))), 1, 4))))
  ) / 7,
  0
)

```

---

<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: [January 3, 2025, 12:15am UTC](https://community.fibery.io/t/done-week-number-formulas/3880/9 "2025-01-03T00:15:36Z")

</div>

> [@interr0bangr](#):
>
> Guess we would create one mega formula if we wanted, right?

Should work fine, I assume.

---

<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: [January 3, 2025, 12:17am UTC](https://community.fibery.io/t/done-week-number-formulas/3880/10 "2025-01-03T00:17:47Z")

</div>

> [@interr0bangr](#):
>
> is there a dedicated “WeekNum” function on the horizon

Yup. Possibly v soon.

---

<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: [January 9, 2025, 3:29pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/11 "2025-01-09T15:29:16Z")

</div>

Formula `IsoWeekNum([Date])` → 23 released today

> [@January 9, 2025 / partying\_face Set any relative value in Date Filter, Batch change fields for selected entities, Improved readability in rich text fields, some new formulas](https://community.fibery.io/t/january-9-2025-set-any-relative-value-in-date-filter-batch-change-fields-for-selected-entities-improved-readability-in-rich-text-fields-some-new-formulas/8082#p-30013-isoweeknumdate-calculate-the-week-number-in-formulas-6):
>
> First release in 2025 brings you some good stuff! partying_face Set any relative value in Date Filter We’ve significantly expanded our Date Filter capabilities to support more flexible time-based filtering. When filtering by Date Field, you can now choose from convenient preset options like “today,” “yesterday,” and “one week from now,” or use the “custom date” option to select either specific dates or relative timeframes. The “is within” operator has also received a major upgrade. You now h…

---

<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: [January 10, 2025, 4:46pm UTC](https://community.fibery.io/t/done-week-number-formulas/3880/12 "2025-01-10T16:46:37Z")

</div>


