Thanks
Norm
There's plenty of utilitities around that do date math and make the
task very straightforward but if you want a straight batch approach
then try this.
@echo off
setlocal
call :get_date
:: Strip leading zeros from possible octals and decrement the day
set /a mm=1%mm%-100, dd=1%dd%-101
if %dd% NEQ 0 goto :add_zeros
:: Today is the 1st of the month - decrement the month
:: and set leap year check (ignoring centuries)
set /a mm-=1,ly=yy%%4
:: If today is 1 Jan, set date to 31st Dec
if %mm% EQU 0 (set /a dd=31, mm=12, yy-=1) else (
rem Calculate days in last month (by Frank Westlake)
set /a "dd=5546>>mm&1,dd+=30"
rem Special case for February
if %mm% EQU 2 if %ly% EQU 0 (set dd=29) else (set dd=28)
)
:add_zeros
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%
echo yesterday was %yy%%mm%%dd%
goto :eof
:: ------------------------------------------------------------------
:Get_Date
:: ------------------------------------------------------------------
:: Generic date parser
:: Sets %dd% (01-31), %mm% (01-12) & %yy% (4 digit)
if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
for /f "tokens=%toks% delims=.-/ " %%d in ('date/t') do (
set %%a=%%d
set %%b=%%e
set %%c=%%f
set toks=
)
)
if %yy% LSS 100 set yy=20%yy%
goto :eof
Garry
>Does anyone have a method for determining yesterday's date in YYYYMMDD
This can be done easily using a language that has a strftime()
function (such as gawk), but it would be easier in batch language just
to get the second newest file in the directory, or better, the oldest
file because you moved all except the current one and the previous one
out of the directory.
for /f "tokens=*" %%a in ('dir /o:-d /b *.log') do set logname=%%a
T.E.D. (tda...@gearbox.maem.umr.edu - e-mail must contain "T.E.D." or my .sig in the body)
With NOWMINUS, via sig line 3;
NOWMINUS D1 F1 J0 R
puts that format on standard output.
I understand that, in NT,
for /f %t in ('NOWMINUS D1 F1 J0 R') do @set XX=%t
would set environment variable XX.
And NOWMINUS D1 F1 J0 Pxx gives SET XX=20021025
which can be redirected to file and executed.
It can make further adjustments, lest you should for example wish to get
yesterday's date any time between 06:30 today & 06:30 tomorrow.
--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
>Does anyone have a method for determining yesterday's date in YYYYMMDD
>format???
Create a file called YESTERDAY.VBS and put these lines into it:
d = DateAdd("d", -1, now)
wscript.echo DatePart("YYYY", d) & _
Right("0" & DatePart("m", d), 2) & _
Right("0" & DatePart("d", d), 2)
Then, put this into your batch file (single line):
for /F %%n in ('cscript.exe //nologo YESTERDAY.VBS') do set
yesterday=%%n
Now you have a variable containing the date in the correct format.
--
Helge Wunderlich
Please remove obvious part of address to send mail
Thanks
Norm
"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message
news:3dba0403...@192.168.0.2...