Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get timestamp in VS code task?

I'm running small shell commands via tasks in VS code.

Within these commands I need the current timestamp.

Given I'm trying to run something like mkdir ./%date in a task:

{
    "label": "make timestamp dir",
    "type": "shell",
    "command": "mkdir ${workspaceFolder}/%date%",
},

I tried using %date% and %time% but both is not substituted.

Alternatively I did see that VS code allows to call commands with ${command:CommandID}. Therefore I installed a extension that generates a timestamp: https://marketplace.visualstudio.com/items?itemName=jsynowiec.vscode-insertdatestring I tried to use that with ${command:insertDateString.insertTimestamp}:

{
    "label": "make timestamp dir",
    "type": "shell",
    "command": "mkdir ${workspaceFolder}/${command:insertDateString.insertTimestamp}",
},

But that also is not substituted.

I'm out of ideas. How to add a timestamp in a VS code task?

like image 364
Spenhouet Avatar asked Jun 16 '26 02:06

Spenhouet


1 Answers

You could try:

  "command": "mkdir -p ${workspaceFolder}/`date +%Y%m%d-%H%M`",

That bash command date works for me. I assume you are using a unix-type shell and that'll work. -p forces it to create the new folder if it doesn't already exist.

See also in vscode how can I quickly generate a new file with datetime in the name?

[I don't know that you want ${workspaceFolder} -that appears to be a full path, maybe you want ${workspaceFolderBasename} but that is a separate issue.]

like image 142
Mark Avatar answered Jun 17 '26 23:06

Mark