'Insert tomorrow's date in a VS Code Snippet

I have an Alfred Snippet that types the outline of a weekly Markdown checklist for me. Here's what it comes out looking like:

## Week (4/25–4/29)
- [ ] 

### Monday Apr 25, 2022
- [ ] Snippet

----

I'd like to move this over to a VS Code Snippet. VS Code defines environment variables like $CURRENT_YEAR and $CURRENT_MONTH_NAME_SHORT that can fill out some of this. But for the "Week (4/25-4/29)" line, I'd really like to have the date for the next Friday (usually four days from today). Is there any way to do this with a VS Code snippet?

For reference, this is how my Alfred is defined:

## Week ({date:M/d}–{date +4d:M/d})
- [ ] 

### Monday {date}
- [ ] Snippet

----


Solution 1:[1]

With the VSC snippets it is not possible.

With the extension File Templates (v1.10.0) you can generate dates/times that are a particular offset from now.

You have to define your preferred dateTimeFormat setting.

Define the following setting (we have a named date format: week-schedule)

Can be Global or in your Workspace

  "templates.dateTimeFormat": {
    "locale": "en-US",
    "options": {
      "year": "numeric",
      "month": "2-digit",
      "day": "2-digit",
      "weekday": "long",
      "hour12": false,
      "hour": "2-digit",
      "minute": "2-digit",
      "second": "2-digit"
    },
    "template": "${month}/${day}"
    "week-schedule": {
      "options": {
        "year": "numeric",
        "month": "short",
        "day": "2-digit",
        "weekday": "long",
      },
      "template": "${weekday} ${month} ${day}, ${year}"
    }
  }

Define the following template (Global or in your Workspace)

week-schedule.md

##@@## ${dateTimeFormat#template=${year}-${month}-${day}#offset=+1WD0 +1D#}_${dateTimeFormat#template=${month}-${day}#offset=+1WD0 +5D#}${input#Additional#find=^(.+)$#replace=-$1#}
## Week (${dateTimeFormat:offset=+1WD0 +1D:}–${dateTimeFormat:offset=+1WD0 +5D:})
- [ ] 

### ${dateTimeFormat:week-schedule:offset=+1WD0 +1D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +2D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +3D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +4D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +5D:}
- [ ] Snippet

----

It will create a filename with the dates and some (optional) additional text.

The first line needs to be that long. The whole filename template must be on line 1.

The template can contain VSC snippets and input fields and a few other variables.


Edit

In v1.11.0 there is a command templates.pasteTemplate where you can insert a Template with a key binding

  {
    "key": "ctrl+alt+w",  // or any other combo
    "command": "templates.pasteTemplate",
    "args": {
      "text": [
        "## Week (${dateTimeFormat:week-schedule-head:offset=+1wd0 +1d:}–${dateTimeFormat:week-schedule-head:offset=+1wd0 +5d:})",
        "- [ ]",
        "",
        "### ${dateTimeFormat:week-schedule:offset=+1wd0 +1d:}",
        "- [ ] Snippet",
        "",
        "----"
      ]
    }
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1