I didn't know that there could be such usage:
C:\>echo %date%
2005-05-10 Tuesday
C:\>echo %date:~0,4%
2005
C:\>echo %date:~11%
Tuesday
C:\>echo %date:~-3%
Tuesday
C:\>echo %date:~-3,-1%
Week
It is the most straightforward way to generate one daily (or one monthly, one year) log file in batch files. It is simpler than applying other methods such as vbscript. The disadvantage of this method is that the value of %date% is different in different systems and language versions. The Regional and Language Options settings in Control Panel will also change the value of %date%.
A few days ago, I had to back up a directory regularly, and I was studying batch files. My idea was to automatically backup the directory and take the current date to backup. Finally, I found a program online:
for /f "tokens=1,2,3 delims=- " %a in ("date /t") in ("date /t") do @echo "%a-%b-%c"
Can take the current date
Great, looking for it!
a -m1 %date:~0,10%\ d:\www\
Every backup will be automatically run in the future!
Thanks!
C:\>echo %date%
2005-05-10 Tuesday
C:\>echo %date:~0,4%
2005
C:\>echo %date:~11%
Tuesday
C:\>echo %date:~-3%
Tuesday
C:\>echo %date:~-3,-1%
Week
It is the most straightforward way to generate one daily (or one monthly, one year) log file in batch files. It is simpler than applying other methods such as vbscript. The disadvantage of this method is that the value of %date% is different in different systems and language versions. The Regional and Language Options settings in Control Panel will also change the value of %date%.
A few days ago, I had to back up a directory regularly, and I was studying batch files. My idea was to automatically backup the directory and take the current date to backup. Finally, I found a program online:
for /f "tokens=1,2,3 delims=- " %a in ("date /t") in ("date /t") do @echo "%a-%b-%c"
Can take the current date
Great, looking for it!
a -m1 %date:~0,10%\ d:\www\
Every backup will be automatically run in the future!
Thanks!