Chase AdamsChase Adams
AboutContentPromptsPlayground

Using Current Date and Time In VS Code Snippets

Essays and updates on product, engineering, and AI by Chase Adams.

1 minute read

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

First Cohort
No Coding Experience Required

Build Your Website with AI—No Code Required

Learn to create and deploy professional websites using ChatGPT and Claude. Go from complete beginner to confident website builder.

Start Building Today

Post Details

Published
Jul 23, 2018
Share
Ask ChatGPT
Ask Claude

Similar Posts

Enable tab completion for Markdown Snippets in VS Code

Enable tab completion for Markdown Snippets in VS Code

in Markdown, VS

AboutAI Workflow SpecContentStacksNewsletterPromptsRSS

Ask me anything

Loading...

Hi! Ask me anything about Chase's work.

I can answer questions based on his blog posts and articles.

Experimental: This chat is a side project I work on in my free time. Responses may vary in quality and accuracy.