Thursday, April 16, 2020

Bash append file to date and time format

Some people would like to export or append your file or log name after the date and time format, like this YYMMDD_MMHHSS.

i have a script it is able to append in this style
@ECHO OFF
set datetime=%date:~0,4%-%date:~8,2%-%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set datetime=%datetime: =0%
echo hello >>%datetime%.txt
EXIT
It will output like this "2020-17-20_104919.txt"

if you don't want the second just modify like this
set datetime=%date:~0,4%-%date:~8,2%-%date:~0,2%_%time:~0,2%%time:~3,2%%time:~4,0%
Resource: 
https://stackoverflow.com/questions/1192476/format-date-and-time-in-a-windows-batch-script

No comments:

Post a Comment