Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
foncesa
- Posts: 42
- Joined: 12 Sep 2013 00:09
#1
Post
by foncesa » 08 Apr 2014 13:09
Hi,
How do i add +1 day in todays date, if today is 08-04-2014 to 09-04-2014
Code: Select all
@echo off
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 "datestamp=%DD%-%MM%-%YYYY%"
echo %datestamp%>>C:\Dates\Tdate.txt
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 08 Apr 2014 18:49
Adjust the variables as needed in the second last line
Code: Select all
@echo off
set day=1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,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 "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "data=%yyyy%-%mm%-%dd%"
echo Tomorrow is "%data%"
-
foncesa
- Posts: 42
- Joined: 12 Sep 2013 00:09
#5
Post
by foncesa » 08 Apr 2014 22:20
Hi,
Thanks to all for helping, supporting.
Thanks a lot.
-
Matt Williamson
- Posts: 82
- Joined: 30 Dec 2013 10:16
- Location: United States by the big waterfall
#6
Post
by Matt Williamson » 09 Apr 2014 05:02
Here is a routine I wrote based upon the date and time functions here. I just merged them together. I've modified it to match your date format.
Code: Select all
@echo off
setlocal
Call :GetDateTime Year Day Month
Echo %Year% %Day% %Month%
Call :AddSubtractDate %Year% %Day% %month% +1 Ret
echo %Ret%
exit /b
:AddSubtractDate Year Month Day <+/-Days> Ret
::Adapted from DosTips Functions::
setlocal & set a=%4
set "yy=%~1"&set "mm=%~2"&set "dd=%~3"
set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
if %yy% LSS 100 set /a yy+=2000 &rem Adds 2000 to two digit years
set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
if %a:~0,1% equ + (set /a JD=%JD%+%a:~1%) else set /a JD=%JD%-%a:~1%
set /a L= %JD%+68569, N= 4*L/146097, L= L-(146097*N+3)/4, I= 4000*(L+1)/1461001
set /a L= L-1461*I/4+31, J= 80*L/2447, K= L-2447*J/80, L= J/11
set /a J= J+2-12*L, I= 100*(N-49)+I+L
set /a YYYY= I, MM=100+J, DD=100+K
set MM=%MM:~-2% & set DD=%DD:~-2%
set ret=%YYYY: =%%MM: =%%DD: =%
endlocal & set %~5=%ret%
exit /b
:GetDateTime Year Month Day Hour Minute Second
@echo off & setlocal
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%"
( ENDLOCAL
IF "%~1" NEQ "" set "%~1=%YYYY%"
IF "%~2" NEQ "" set "%~2=%DD%"
IF "%~3" NEQ "" set "%~3=%MM%"
IF "%~4" NEQ "" set "%~4=%HH%"
IF "%~5" NEQ "" set "%~5=%Min%"
IF "%~6" NEQ "" set "%~6=%Sec%"
)
exit /b
-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#7
Post
by Dos_Probie » 09 Apr 2014 06:36
Note: If running Windows 7 to 8.1 you may need to runas admin on your batch or better yet just add a admin script to your code..DP