Background Vector
Background Vector

Find the preceding Sunday (or Monday, or…)

Often we are asked to produce reports that show total sales (or student attendance, or whatnot) by week. In order to produce these reports, we need some value that allows us to group our records by week. What we can use is the Sunday—the start of our week—that occurs before our activity date.

For example, let’s say we had sales records for the month of January, 2010. January started on a Friday; if we take 1/1/2010, we can “reduce” it to the preceding Sunday—12/27/2009.  Similarly, Saturday the 2nd also falls in the week beginning 12/27/2009.  On Sunday we start a new week: January 3rd through the 9th all fall in the week starting 1/3/2010.  Once we have found the date for the start of the week for each sale, we can group our sales by that date and produce our report.

The formula for finding the preceding Sunday for a date (unless said date is a Sunday, in which case we just want that date) is very simple.  Dates can be treated as numbers, and Sundays happen to be evenly divisible by seven.  Basically, we find the most recent date before our given date that is evenly divisible by seven by dividing said date by seven, throwing away any remainder, and multiplying back by seven:

Div ( date ; 7 ) * 7

But what if you want to run your weeks from Monday to Sunday, and need to find the preceding Monday instead? You can’t just add one to the preceding Sunday, because you’d get weird results when activity fell on a Sunday (simply adding one to the above formula gives you the following Monday when date is a Sunday). You need to do a little “shifting” first to your original date, subtracting the offset between Sunday and Monday, finding the preceding Sunday for this earlier date, and then adding back the offset to find the Monday to start your week.

Div ( date - 1 ; 7 ) * 7 + 1

Similarly, if you want to start your week on Tuesday for some reason, you just use an offset of 2:

Div ( date - 2 ; 7 ) * 7 + 2

Finding the start of the week for dates is useful for more than just summary reports.  If you’ve ever wanted to create a calendar interface in FileMaker, you’ll use similar formulas along the way.  In fact, I may have something to say about calendars and FileMaker Pro 11 soon…

 

Related Articles

AI and FileMaker working together for custom business software development

Let’s be honest: AI isn’t going anywhere. The powerful LLM tools that Anthropic, OpenAI, Google, and others have developed are here to stay. They are increasingly becoming integrated into our everyday lives, especially in the software development world. And there

Team collaborating on business reporting using a flexible FileMaker application
Business requirements change. Learn why FileMaker makes it easy to adapt reports, workflows, and databases without lengthy development cycles.
Illustration of AI connecting FileMaker 2026 with multiple business systems using intelligent data workflows.

Last month, we explored the most impactful developer-focused features in FileMaker 2026: from Remote Backup and Standby Server to native PDF generation and other enhancements that make building and maintaining applications easier. But there was one topic we didn’t touch