Reputation: 1945
If my system date is 25/09/2019 and time is 08.12 then i want output from batch file as 250920190812
But this code gives me 01 as output if i want to get day of todays date which is 25
echo Current day %date:~7,2%
What is wrong?
Upvotes: 0
Views: 712
Reputation:
System Locale differs on each system, so rather use something more robust that will give consistant results on each device, for instance here is an example that also incorporates vbs.
@echo off
echo >"%temp%\%~n0.vbs" s=DateAdd("d",0,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "mydate=%%a"
set dd=%mydate:~6,2%
set mm=%mydate:~4,2%
set yyyy=%mydate:~0,4%
set mytime=%time::=%
set mytime=%mytime: =0%
echo %dd%%mm%%yyyy%%mytime:~0,4%
del "%temp%\%~n0.vbs" /Q
Upvotes: 1