Zoho Deluge: Get the Week Number if Week starts on a Monday
- Joel Lipman
- Zoho
- Hits: 1533
A quick article on determining the week number of the year if your week starts on a Monday and not a Sunday.
Why?
I think it's the US system which generally says that a week starts on a Sunday but in the United Kingdom, the week generally starts on a Monday. So let's say there's a schedule that has to be run weekly and include all the orders of a specific week...
Just to confuse everyone in the world, the day index for a Sunday is 7 (ie. myDate.toString("u") returns 7) and the week commences on a Sunday (ie. myDate.toStartOfWeek("EEEE") returns Sunday). In other words, the day counting starts at 7, followed by 1 for Monday, 2 for Tuesday, and so on...
How?
The logic behind this would be to take the date of the order, check if the order date is a Sunday, subtract a day, and return the week number: