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

months...

1 view
Skip to first unread message

Andy

unread,
Nov 7, 2001, 7:41:44 PM11/7/01
to
1000 apologies if this has been answered oodles of times before in the
newsgroup. But yes, I am using NT/2000 (I suppose it should be 2000
apologies?) and what I want to do is a change directory (cd) to the
current month in the batch file

e.g. cd c:\myfiles\%<month>%.

Now, I don't care if <month> is 11 for november or Nov or whatever,
but I am having difficulty just getting the two digits out of the date
environment variable.

I have found lots of stuff about creating filenames based on date and
time and replacing slashes with fantastic FOR loops and all others
things but I have not found anything yet that says "OK forget the rest
of date, I just want the month part..." (and again it can be 11 or Nov
- if its 11 I am sure I can do a 'case' to get to Nov!!)

If anyone has the solution, I would be v grateful.

Ta v m

Phil Robyn

unread,
Nov 7, 2001, 8:12:50 PM11/7/01
to

The following is predicated upon the assumption that 'date /t' produces
output like 'Wed 11/07/2001' (American date setting of 'Day mm/dd/yyyy'):

01. @echo off
02. setlocal
03. for /f "tokens=2 delims=/ " %%a in (
04. 'date /t'
05. ) do set /a MM=1%%a - 100
06. for /f "tokens=%MM%" %%a in (
07. "January February March April May June July August
08. September October November December"
09. ) do set MONTH=%%a
10. set MONTH

If your date format is 'Day dd/mm/yyyy', then in line 3 you would have
to change 'tokens=2' to 'tokens=3'.

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

0 new messages