%DATE% Batch Variable not working in Windows 10
I created a batch file:
@ECHO OFF
C:
MKDIR C:\BACKUP
CD C:\BACKUP
ECHO backing up, plz wait...
MKDIR bkup-%date%
cd bkup-%date%
But I get an error saying: "The syntax of the command is incorrect." error.
Please help me, thanks.
Solved!, I found a post:
set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%
echo datetimef
This solve my issue, thanks.
rem only WINDOWS 10
CLS
@echo off
ECHO %DATE%
ECHO.
ECHO %TIME%
ECHO.
set mydate=%date:~11,4%-%date:~8,2%-%date:~5,2%
echo %mydate%
PAUSE
EXIT
On my system, the format of the date when you used %date%
on Windows 8 was MM/dd/yyyy
(eg 02/23/2016
) but after upgrading to Windows 10 it displayed as Day MM/dd/yy
(eg Tue 02/23/16
) instead. This caused /
characters in folder paths in my script which made it fail. In the Start > Settings > Time & Language > Date & time
settings, I noticed that the format for Short date
had changed to the M/d/yy
option. When I reset the option to MM/dd/yyyy
the format for %date%
returned to MM/dd/yyyy
and my program which grabbed the date parts based on that format worked properly again.
If you want to set a custom date format, you can go to Region > Additional settings... > Date tab
and set a custom format for Short date
which will then be used for the command prompt %date%
printout.
I had the same problem. I solved it using %%B
instead of %date%
(Leonardo's answer didn't work for me on windows 7). Example
使用字符替换:%date:/=-%
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.