Skip to content

Instantly share code, notes, and snippets.

@paul-d-ray
Last active September 20, 2025 03:07
Show Gist options
  • Select an option

  • Save paul-d-ray/6b4ef1785f74f212e3f72a4943e644e4 to your computer and use it in GitHub Desktop.

Select an option

Save paul-d-ray/6b4ef1785f74f212e3f72a4943e644e4 to your computer and use it in GitHub Desktop.
Nushell Get First Monday of Each Month of a Year

First Monday of Each Month

I had a need to get the first Monday of each month of 2025.

  • This can be changed to get any other first day by changing the wday variable.
    • su, mo, tu, we, th, fr, sa

Nushell Code

let wday = 'mo'
let year = 2025

cal -m -t --week-start $wday --full-year $year
| group-by month
| items {|mon cal|
    let first_monday = ($cal
        | where {|row| $row | get $wday | is-not-empty }
        | first
        | get $wday)

    {
      Monday: ($"($year)-($mon)-($first_monday)" | format date "%F")
    }
}

Output

╭────┬────────────╮
│  # │   Monday   │
├────┼────────────┤
│  0 │ 2025-01-06 │
│  1 │ 2025-02-03 │
│  2 │ 2025-03-03 │
│  3 │ 2025-04-07 │
│  4 │ 2025-05-05 │
│  5 │ 2025-06-02 │
│  6 │ 2025-07-07 │
│  7 │ 2025-08-04 │
│  8 │ 2025-09-01 │
│  9 │ 2025-10-06 │
│ 10 │ 2025-11-03 │
│ 11 │ 2025-12-01 │
├────┼────────────┤
│  # │   Monday   │
╰────┴────────────╯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment