Skip to content
Kuovonne's Guide to Scripting in Airtable
  • Pages
    • Kuovonne's Guide to Scripting in Airtable
      • So you want to learn Scripting?
        • Do you just want working code?
        • Can AI write my script?
        • Where do I start?
        • Kuovonne's coding journey (part 1)
      • Free Scripts
        • Formatted Timestamp
        • Interface Sidesheet Url
        • 2nd & 4th Monday of each Month
        • Copy value from one field to another
      • Examples of designing coding solutions
        • Tossed Salad Junction Records
      • Object IDs in Airtable
      • Automation Scripts
        • Converting a script to run as an automation
        • Automation script limits
      • Developing Generic Coding Skills
        • Traits of Quality Code
        • Reading Documentation
        • Using Variables
        • Debugging & Testing
        • Not Time Wastes
        • Comments in Code
      • Possible future topics

2nd & 4th Monday of each Month

Your donations tell Kuovonne that you value her content and want her to continue publishing.

Inspiration

The inspiration for this script came from a .
Someone wanted to schedule an automation to go out on the 2nd and 4th Monday of each month. While you can schedule an Airtable automation to run every two weeks, that solution won’t work because the schedule will be off as soon as a month has five Mondays in it.
I gave two suggestions ...
I can think of two approaches:
(Option 1) Schedule the automation to run every Monday. Have a scripting action that calculates if it is the 2nd or 4th Monday and outputs the result. Have rest of the automation in a condition based on the script output.
(Option 2). Have a control table with two records. One record for the 2nd Monday of the Month, and another record for the 4th Monday of the month. Use a formula field to calculate the actual date. Use a “when record meets conditions” trigger.
This script discusses how to write the script in Option 1.

Discussion

First get the current date.
const date = new Date()
We don’t need to get the day of the week because the automation is scheduled to run on Mondays.
However, we do need to know the day of the month to determine which Monday it is in the month (1st, 2nd, 3rd, 4th, or 5th)
const dayOfMonth = date.getDate()
If the day of the month is 1-7, it must be the first Monday of the month. If the day of the month is 8-14, it must be the second Monday of the month. And so on.
let dayOfWeekOcurrance
if (dayOfMonth <= 7) {
dayOfWeekOcurrance = 1
} else if (dayOfMonth <= 14) {
dayOfWeekOcurrance = 2
} else if (dayOfMonth <= 21) {
dayOfWeekOcurrance = 3
} else if (dayOfMonth <= 28) {
dayOfWeekOcurrance = 4
} else {
dayOfWeekOcurrance = 5
}
However, that long else if chain is a bit unwieldy. A shorter way is to divide by 7 and round up to a whole number.
const dayOfWeekOcurrance = Math.ceil(dayOfMonth / 7)
Finally, output the value to be used in a future automation action.
output.set("dayOfWeekOcurrance", dayOfWeekOcurrance)
Here is the full script.
const date = new Date()
const dayOfMonth = date.getDate()
const dayOfWeekOcurrance = Math.ceil(dayOfMonth / 7)
output.set("dayOfWeekOcurrance", dayOfWeekOcurrance)
You can now use the output of that script in a condition group later in the automation.
image.png
The content in this guide is free, but creating it takes time and money. If you like this content, .

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.