Computing.Net > Forums > Windows 2000 > Batch to get DATE and then change..

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch to get DATE and then change..

Reply to Message Icon

Name: ikerstges
Date: January 19, 2006 at 05:04:23 Pacific
OS: Windows 2000
CPU/Ram: PIII650/512
Comment:

Hi,

I have a batchfile that stores DATE elements in separate variables:

FOR /F "tokens=1,2,3,4 delims=/- " %%a in ('date/T') do set CDATE=%%c%%b%%a

Running this line gives me following results on the server:
%%a= 19
%%b= Jan
%%c= 06
%CDATE%= 06Jan19

The server is restricted to it's current regional and date/time settings due to application requirements. I would like to have %CDATE% show a different result.

Desired result: %CDATE%= 20060119

I can change the year by applying:
FOR /F "tokens=1,2,3,4 delims=/- " %%a in ('date/T') do set CDATE=20%%c%%b%%a

My problem is: can I somehow convert the month characters (Jan-Feb-Mar-Apr-May-Jun-Jul-Aug-Sep-Oct-Nov-Dec) into their respective number?

Any help would be highly appreciated!



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 19, 2006 at 09:45:43 Pacific
Reply:

There must be some elegant solution; but I don't know what it is.

So I'd just brute-force it; like this:

if %m%==jan set m=01

etc


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: FishMonger
Date: January 19, 2006 at 23:32:54 Pacific
Reply:

If you're willing to use something other than a batch file, I can show you how easy this is to do in Perl.

$cdate = strftime("%Y%m%d", localtime);


0

Response Number 3
Name: ikerstges
Date: February 8, 2006 at 03:17:08 Pacific
Reply:

Yeah, I have implemented Mechanix's suggestion. Unfortunately, PERL isn't an option, as that would have been much slicker!

Thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: Batch to get DATE and then change..

Excel Formula...Date and then count www.computing.net/answers/windows-2000/excel-formuladate-and-then-count/48175.html

batch file to get date/time of file www.computing.net/answers/windows-2000/batch-file-to-get-datetime-of-file/60888.html

autoupdate networkdriver www.computing.net/answers/windows-2000/autoupdate-networkdriver/27606.html