Extract Week Starts on Monday?

When I extract a week number from a date it seems to be starting the week from Monday, not Sunday.

image

I know the question on this forum is usually how to adjust the week start forward to Monday, but in this case I want it to be Sunday and I’ve no idea why I’m seeing this behavoir.

Any ideas?

For clarity, Week 42 started on 13/10/2024 for the purposes of this application.

As per the ISO-8601 standards, the Week starts on Monday.

What's the Current Week Number?.

Week 42 is from Monday, October 14, 2024 until (and including) Sunday, October 20, 2024.

But if you want your app to include Sunday from the Previous week as part of the next week you can just add 1 to the extracted Week if the day is a Sunday (although that may confuse people, as it’s actually incorrect).

I am very much from the part of the world that aligns to this standard, however the American firm we work with…does not.

Hey ho.

The conditional is a good idea, I’ll give that a go, thank you.

1 Like

Interesting. Then why does Bubble return 0 for Sunday and 1 for Monday and so on when we ‘extract day’ from a date?

1 Like

Because in Bubble.io, as in JavaScript, and many other programming languages (although not all), a Week starts on Sunday:

Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6

But the ISO 8601 standard doesn’t care about JavaScript (or any other specific language).

In vanilla Javascript there is no built in way to establish the Week from a given Date, but libraries like Luxon.js or (the outdated/deprecated) moment.js (which is what Bubble still uses for Dates) have built in methods for getting the week of given Date, which follow the ISO standard of Weeks (at least in the context of establishing the week number) starting on Monday.

Confusing? yep… (dates/timezones really are…)

2 Likes

Thanks @adamhholmes for detailed explanation.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.