I don\'t know much about windows .bat file syntax. My simple requirement is to create a folder at a specific location with name as current date. I tried searching this on go
mkdir %date:~-4,4%%date:~-10,2%%date:~7,2%
G:
cd G:/app/
mkdir %date:~7,2%%date:~-10,2%%date:~-4,4%
cd %date:~7,2%%date:~-10,2%%date:~-4,4%
sqlplus sys/sys as sysdba @c:/new
If your locale has date format "DDMMYYYY" you'll have to set it this way:
set datestr=%date:~-4,4%%date:~3,2%%date:~-10,2%
mkdir %datestr%
You need to get rid of the '/' characters in the date before you can use it in mkdir like this:
setlocal enableextensions
set name=%DATE:/=_%
mkdir %name%
https://stackoverflow.com/a/31789045/1010918 foxidrive's answer helped me get the folder with the date and time I wanted. I would like to share this method here since it worked great for me and I think it could help other people too, regardless of their locale.
rem The four lines below will give you reliable YY DD MM YYYY HH Min Sec MS variables in XP Pro and higher.
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" & set "MS=%dt:~15,3%"
set "dirname=%YYYY%-%MM%-%DD% %HH%-%Min%-%Sec%"
:: remove echo here if you like
echo "dirName"="%dirName%"
This works for me, try:
ECHO %DATE:~7,2%_%DATE:~4,2%_%DATE:~12,2%