Bases: Snippet for Grouping By/Displaying a Week's Range

Disclaimer

Is this project open source? Yes
Is this project completely free? Yes
Is this project made with AI beyond the author’s ability to comprehend how it works? No


To group by a week’s range (e.g., Sun, Aug 30th - Sat, Sep 5), and to sort by these weeks, lead the range with the year and month (e.g., September of 2026 = 2026-09) with a format like the following Bases formula:

(file.mtime.date() + ((6 - Number(file.mtime.format("e"))) + "d").toString()).format("(YYYY-MM) ") 
+ (file.mtime.date() - ((Number(file.mtime.format("e"))) + "d").toString()).format("ddd, MMM DD") 
+ " - " 
+ (file.mtime.date() + ((6 - Number(file.mtime.format("e"))) + "d").toString()).format("ddd, MMM DD")

Hello,

I this your formula is a little complex

Thank you for looking at my post! If it helps, this script works by…

  1. Taking the number “day of the week” in moment.js (represented by e; which is 0 for Sunday, 1 for Monday, until 6 for Saturday) and converts it to a number.
  2. Either taking the day of the week and subtracting it (to find the “previous Sunday” or adding “6 - day of the week” to find the “next Saturday”).
  3. Converting it to a day by concatenating “d” to the number, and subtracting/adding it to the date the file was modified.
  4. The formats (.format()) are based off of moment.js and Obsidian Bases syntax, which you can find here: Moment.js | Docs