Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

# How can I group the weeknum function for a specific month only?

Solved
304 5
cancel
Showing results for
Did you mean:
5 - Automation Enthusiast

Hey!
I was trying to group the weeks by the month, so like if I have a Date, I want to get the weeknum in which the date falls WITHIN that specific month only.
Eg. - 1/6/22 - it should show as 1 - since it comes in 1st week of June.

I read up and tried to use the following formula -
MONTH(TODAY(WEEKNUM(NOW())))

However, its giving the output as 6(?!) I think its because its counting 26th May till 2nd June as a week.

Is there any workaround to this please?

1 Solution

Accepted Solutions

Hi Mayank, the `TODAY()` function doesn’t take any arguments, so the formula of `MONTH(TODAY(WEEKNUM(NOW())))` only does the following:

`MONTH(TODAY())` and ignores `WEEKNUM(NOW())`

As a result, you’re getting the output of 6 as, at the time of writing, `NOW()` is the first of June, the sixth month of the year.

To achieve what you’re looking for, try the following formula:

``````WEEKNUM({Date})
-
WEEKNUM(DATETIME_PARSE(YEAR({Date}) & "-" & MONTH({Date}) & "-01", 'YYYY-MM-DD'))
+ 1
``````
5 Replies 5
5 - Automation Enthusiast

Attaching SS for reference-

Hi Mayank, the `TODAY()` function doesn’t take any arguments, so the formula of `MONTH(TODAY(WEEKNUM(NOW())))` only does the following:

`MONTH(TODAY())` and ignores `WEEKNUM(NOW())`

As a result, you’re getting the output of 6 as, at the time of writing, `NOW()` is the first of June, the sixth month of the year.

To achieve what you’re looking for, try the following formula:

``````WEEKNUM({Date})
-
WEEKNUM(DATETIME_PARSE(YEAR({Date}) & "-" & MONTH({Date}) & "-01", 'YYYY-MM-DD'))
+ 1
``````
5 - Automation Enthusiast

Hey Adam, could you please explain how this worked?
I’m not able to understand.

Hi Mayank, it works by finding out the week number of the date value we give it, and then deducting the week number of the first week of the month of said date value

Consider a date value of 5 June

Its week number is 23.
The week number of the first week of the month of June is 23.

We deduct 23 from 23 and since the result is 0 we know it’s the first week of the month

We then add 1 to it purely for display purposes, as having ‘0 week of the month’ isn’t intuitive

5 - Automation Enthusiast

Thanks for this. Very helpful.