Date-time in Windows command

By default the command echo %date%-%time% spits out something like this on my PC: 16/01/2023-16:34:14,65. Not very useful as part of a filename. You can format the string by grabbing parts of the variable – one at a time – with a command like shown here…

echo %date:~6,4%%date:~3,2%%date:~0,2%-%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%

The output provided by this example is 20230116-16341465

1 Comments

Leave Comment

Your email address will not be published. Required fields are marked *