Yesterday' Date

T

Tim

I've written an expression in that allows me to rename a
file with the current date stamp.

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set Today=%%a-%%b-%%c)
rename c:\winzip.log winzip%TODAY%.log

The output generated would be: winzip10-09-2003.log

My problem is that, since the data that is renamed is actually
yesterday's data, the date is always one day ahead of the date that
the data actually represents.

I want it to read: winzip10-08-2003.log

My question is: Is there a way to automatically rename a file with
yesterday's date?

Any help would be appreciated.

Thank you.
 
M

Michael Bednarek

On 9 Oct 2003 05:02:33 -0700, (e-mail address removed) (Tim) wrote in
microsoft.public.win2000.cmdprompt.admin:

[snip]
My problem is that, since the data that is renamed is actually
yesterday's data, the date is always one day ahead of the date that
the data actually represents. [snip]
My question is: Is there a way to automatically rename a file with
yesterday's date?

As I wrote earlier
<http://groups.google.com/[email protected]>
in alt.msdos.batch.nt:

Simple. Using a different CLI (4NT), this is what I do:
SET yesterday=%@MAKEDATE[%@EVAL[%@DATE[%_isodate]-1],4]

Screenscrape :
$ ECHO Today is: %_isodate; 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://jpsoft.com/help/_isodate.htm,
..../f_date.htm, .../f_eval.htm, and .../f_makedate.htm, respectively.

Other options are specialised utilities to perform date arithmetic, or
rather elaborate batchfiles if you want to restrict yourself to CMD's
limitations.
 
M

Marty List

Ritchie said:
<http://groups.google.com/groups?threadm=t7hqfvoshk8rm4kfh74qhs3ebush5burh7%
404ax.com>

It doesn't matter how many times you harp on about 4NT, you've still got to
buy and install it on every machine you want to use it and then learn another
language.

I agree with you Ritchie. 4DOS/4NT are awesome products, but I move around
to so many machines I can't really rely on it for very many things. It
would be really cool if Microsoft were to work out a license agreement to
either include the product with the OS or actually include the functionality
in CMD.EXE.
 
H

Helge Wunderlich

My question is: Is there a way to automatically rename a file with
yesterday's date?

With VBscript, it's simple:

Create yesterday.vbs, containing these five lines:

Y = Now - 1
WScript.Echo Pad2(Month(Y)) & "-" & Pad2(Day(Y)) & "-" & Year(Y)
Private Function Pad2(Inp)
Pad2 = Right("00" & Inp, 2)
End Function

Then, in your batch file, get the output like this:

for /F %%a in ('cscript //nologo yesterday.vbs') do set Yesterday=%%a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top