how to get current day of todays date in batch file

拟墨画扇 提交于 2020-01-16 09:12:17

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/58092146/how-to-get-current-day-of-todays-date-in-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!