DEV Community

Cover image for Using Current Date and Time In VS Code Snippets
Chase Adams
Chase Adams

Posted on • Originally published at chaseadams.io on

8

Using Current Date and Time In VS Code Snippets

Previously when generating new blog articles, 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\"
Enter fullscreen mode Exit fullscreen mode

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

date: "2018-07-24"
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (2)

Collapse
 
malcolmkee profile image
Malcolm Kee

Thanks for this :)

Collapse
 
integr8or profile image
Mark Stouffer

I don't see the snippet, "fm"?

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more