Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

subtract 1 day from current in a date variable

7 views
Skip to first unread message

Steve

unread,
Jun 27, 2003, 3:18:09 PM6/27/03
to
All,

This is what I have for the current date variable environment. How do I
create another date variable environment that is a day less than the
current one?

for /f "tokens=2" %%a in ('date /t') do set zdate=/%%a
set zdate=%zdate:/0=/%
set zdate=%zdate:~1%


Thanks,

Steve


Ted Davis

unread,
Jun 27, 2003, 4:46:14 PM6/27/03
to

This is extremely difficult in most languages that don't have tiem
functions based on a long integer count of seconds from some epoch.

An easy way is to have the scheduler run a batch file each day that
creates a file in a directory after moving the existing file to
another directory after deleting the file in the other directory. The
file in the second directory was created yesterday and can easily
contain yesterday's date and any other material you need.

T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

Michael Bednarek

unread,
Jun 28, 2003, 3:50:58 AM6/28/03
to
On Fri, 27 Jun 2003 14:18:09 -0500, "Steve" <stp...@qwest.net> wrote
in alt.msdos.batch.nt:

Simple. Using a different CLI (4NT), this is what I do:

SET today=%_isodate
SET yesterday=%@MAKEDATE[%@EVAL[%@DATE[%_isodate]-1],4]

Screenscrape :
$ ECHO Today is: %today; yesterday was: %yesterday
Today is: 2003-06-28; yesterday was: 2003-06-27

The variable _isodate and the functions @DATE[], @EVAL[], and
@MAKEDATE[] are documented at http://www.jpsoft.com/help/_isodate.htm,
.../f_date.htm, .../f_eval.htm, and .../f_makedate.htm, respectively.

--
Michael Bednarek, IT Manager, Tactical Global Management
Waterfront Pl, Brisbane 4000, Australia. "POST NO BILLS"
http://mcmbednarek.tripod.com/

Phil Robyn

unread,
Jun 28, 2003, 11:54:25 PM6/28/03
to

You can do this pretty easily by using Windows Scripting Host.

<Win2000> c:\cmd>wshcalcdate today -1 .
2003/06/27

<Win2000> c:\cmd>currver wshcalcdate qblist
===== begin file c:\CMD\TEST\wshcalcdate.cmd =====
01. @echo off
02. setlocal
03. set date1=%1
04. set qty=%2
05. if /i "%date1%" EQU "TODAY" (
06. set date1=now
07. ) else (
08. set date1="%date1%"
09. )
10. echo>%temp%\%~n0.vbs Set fso=CreateObject("Scripting.FileSystemObject")
11. echo>>%temp%\%~n0.vbs s=DateAdd("d",%qty%,%date1%)
12. echo>>%temp%\%~n0.vbs set newfile = fso.OpenTextFile("%temp%\%~n0.bat", 2, True)
13. echo>>%temp%\%~n0.vbs newfile.WriteLine "@set zdate="^&year(s)^&"/"^&right(100+month(s),2)^&"/"^&right(100+day(s),2)
14. echo>>%temp%\%~n0.vbs newfile.close
15. cscript //nologo %temp%\%~n0.vbs
16. call %temp%\%~n0.bat
17. if "%3" EQU "." echo %zdate%
18. endlocal&set %~n0=%zdate%
===== end file c:\CMD\TEST\wshcalcdate.cmd =====

<Win2000> c:\cmd>wshcalcdate today -123456 .
1665/06/23

<Win2000> c:\cmd>set wshcalcdate
wshcalcdate=1665/06/23

<Win2000> c:\cmd>wshcalcdate %wshcalcdate% +123456 .
2003/06/28


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Dr John Stockton

unread,
Jun 29, 2003, 2:06:29 PM6/29/03
to
JRS: In article <RL0La.49$a_6....@news.uswest.net>, seen in
news:alt.msdos.batch.nt, Steve <stp...@qwest.net> posted at Fri, 27 Jun
2003 14:18:09 :-

>
>This is what I have for the current date variable environment. How do I
>create another date variable environment that is a day less than the
>current one?

For yesterday's date,

for /f %t in ('NOWMINUS f1 d1 r') do @set YESTERDAY=%t

should, AIUI, set YESTERDAY to yesterday's date; but I cannot test it in
NT. Get NOWMINUS.ZIP via sig line 3.

NOWMINUS can also read environment variables, handle various date & time
formats, and do other date/time arithmetic. It can thus start with a
"current" date that is not today's date.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Garry Deane

unread,
Jun 29, 2003, 9:11:29 PM6/29/03
to

See here for a batch only solution.
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3dba0403.1229808%40192.168.0.2

Or take a look at
http://www.commandline.co.uk/cmdfuncs/dandt/index.html for various
batch date and time functions that will allow date maths.

Garry

0 new messages