Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
within a batch file, Is there a way to set a variable to be equal to the system date minus seven days?

i wrote a small calculater for dos, you can use it in a batchfile, if you firm with batchfile programming, you can use it for that problem, if not -> mail me
download SCALC.COM under downloads from http://plop.at

Bitbyte's SCALC.COM is a great program, useful on batch files under DOS/Win9x. However, in NT systems such as Win 2000, the command prompt itself can do all it does (and much more). Here's a sample:
set DAY=30
set /A DAY -= 7For more information about doing arithmetic operations with the SET command, type "SET/?" on the command prompt.
However, that still doesn't solve all your problem, that's actually the easy part. You gotta get the date, subtract 7 from the day, and do the necessary calculations if the new resulting day is less than 1. Such calculations aren't that simple, you gotta calculate the new month, calculate the new date based on that, sometimes check if the year has a 29-day-february, etc. The following batch file will do it:
@echo off
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do (
set M=%%A
set D=%%B
set Y=%%C
)if "%D:~0,1%"=="0" set D=%D:~1%
if "%M:~0,1%"=="0" set M=%M:~1%:: Subtract the desired number of days
set /A D -= 7:arrange
if %D% GTR 0 goto dateOK
set /A M -= 1
set /A BX = %Y% %% 4
if %M% GTR 0 goto keepyear
set /A Y -= 1
set /A M += 12
:keepyear
for %%? in (1 3 5 7 8 10 12) do if %M% == %%? set /A D += 31
for %%? in (4 6 9 11) do if %M% == %%? set /A D += 30
if %M% == 2 (
if %BX% EQU 0 set /A D += 29
if %BX% NEQ 0 set /A D += 28
)
goto arrange
:dateOK
if "%D:~1%"=="" set D=0%D%
if "%M:~1%"=="" set M=0%M%The variables are M D and Y, with month and date with 2 digits and year with 4.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br__________________________________________________________________

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |