Notion app logo
Struggling to stay organized and effective? Learn to master your time and tasks with the Effectively Notion course!

Using Current Date and Time In VS Code Snippets

Learn how to use current date and time in VS Code Snippets.

2018-07-24

Previously when generating new blog articles (inVS Code, now I generate articles in Obsidian), adding dates to Markdown frontmatter was a manual step that required me to:

  • Determine the date
  • Convert what I read into the date format I use for frontmatter

As of VS Code release 1.20, Snippets have access to the current date and time with one of the following variables:

  • CURRENT_YEAR
  • CURRENT_YEAR_SHORT
  • CURRENT_MONTH
  • CURRENT_DATE
  • CURRENT_HOUR
  • CURRENT_MINUTE
  • CURRENT_SECOND

Now if I want a frontmatter "date" for Markdown for the current year, month and day (YYYY-MM-DD), I can add the following to my snippet:

date: "\"$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE\""

Using the published date of this post, the expanded snippet produces:

date: "2018-07-24"

Markdown snippet with current date and time automatically inserted

Photo of Chase Adams

Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.

Freebies

Vector Arrow Scribbles
banner image for figma vector arrows scribbles

A figma community project of vectorized hand-drawn arrows.

Go To Figma
Vector Line Scribbles
banner for figma vector line scribbles

A figma community project of vectorized hand-drawn lines.

Go To Figma
Vector Shape Scribbles
banner image of figma vector shapes scribbles

A figma community project of vectorized hand-drawn shapes.

Go To Figma

Subscribe to my Newsletter

Every other week I publish the Curiously Crafted newsletter.

In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.

Online

I'm on almost all social media as @curiouslychase.

The curious logo of Chase Adams: glasses and a bow tie.stay curious.