Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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%= 06Jan19The 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%%aMy 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!

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

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);

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

![]() |
![]() |
![]() |

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