Extract week of month

Hi!

I know we can extract the number of week/year but can we extract the number of week/month?
I am stuck trying to figure out if this is possible but I can not find a way.

Best regards,

Jorge

1 Like

Hello @jorgemartcaam,

not with Extract Date&Time Fields node but I guess it shouldn’t be a problem to do so with couple of nodes. Can you describe logic for week/month calculation?

Br,
Ivan

Hi @ipazin,

An image is worth a thousand words…
image

Best regards!

Jorge

1 Like

Hello @jorgemartcaam,

indeed it does. Here is workflow example:
2021_06_23_Week_of_Month.knwf (20.5 KB)

If you are doing this for more than one year extract year as well so you can add it as grouping column in Group Loop Start. Same can be achieved in one node by scripting (Column Expressions, Java Snippet, Python…) but I’ll leave this to someone else if interested. If any questions feel free to ask.

Br,
Ivan

4 Likes

Nice! Thank you.
If I understand the workflow correctly, you are just working within the months (hence the loop) and adding up each sunday, right?

Best regards.

You are welcome. Correct, adding 1 where name is Sunday and in first row, then performing cumulative sum.
Ivan

1 Like

So…
I’ve been implementing your solution but I have several problems.
1- My database does not have saturdays nor sundays. I tried using mondays in the rule engine node but the problem is that the workflow will not have into account the weeks of the month that start after a monday.
For example, april starts on a thursday and the first monday is a 5. This way I am not taking into account those days. Tried it with fridays but with similar result.

image image

2- The second problem: I can have up to 15 weeks in a month. That happens because my database has three groups. “Empresas”, “No vida” and “Vida”, each of which has its own date. As before, an image is worth…

So… The problem is harder than I expected.

Hello @jorgemartcaam,

not too much. See modified example:
2021_06_23_Week_of_Month.knwf (32.1 KB)

First part in annotation is only data preparation to have data as you do. Second part is modified to account 3 groups and Sundays/Saturdays missing. Monday in Rule engine should work just fine.

Br,
Ivan

4 Likes

Yep. A couple of tweeks and perfect!
I think :laughing:

Thank you!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.