remove some characters in a text file

October 28, 2009 at 09:45:23
Specs: Windows XP pro, P4/512
I am trying to get the date in YYMM format and I need to make that a variable for use elsewhere in my current batch file. So far I am using date /t and a for /f loop to filter it. I am not having luck so far. What I have now is:

@echo off
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Year=%%C

echo %Year% >date.txt
echo %Month% >> date.txt

then I was gonna do another for /f to take out the extra 2 numbers in the year and re-organize them into the desired YYMM format. but there has to be a better way and I figured you guys would know. Thanks in advance :)

See More: remove some characters in a text file

Report •

October 28, 2009 at 09:56:57
Wow, seems like you are doing it the hard way. Just concat the vars...

@Echo off
Set Month=%Date:~-10,2%
Set Year=%Date:~-2,2%

echo %Year% >date.txt
echo %Month% >> date.txt

Report •

October 28, 2009 at 10:11:14
That works thanks! I just changed the last 2 lines to

echo %Year%%Month% >date.txt

So I can get the format I need. I wish I could say I knew what you were doin there but I dont. I understand concat but not the code that is doin it.

Thanks again

Report •

October 28, 2009 at 10:26:18
In this command...

Set Month=%Date:~-10,2%

You are copying the characters from the right -10 character. This set the pointer to where you want to start copying. The 2 sets how many characters you want to copy. So the full %Date% looks like....

Wed 10/28/2009

-14,1 = W 
-13,1 = e
-12,1 = d
-11,1 = 
-10,1 = 1
 -9,1 = 0
 -8,1 = /
 -7,1 = 2
 -6,1 = 8
 -5,1 = /
 -4,1 = 2
 -3,1 = 0
 -2,1 = 0
 -1,1 = 9

Make seance now?

P.S. When I said Concatenate I meant Pars because concatenate means put together and pars means separate.

Report •

Related Solutions

October 28, 2009 at 11:02:57
yea its actually pretty simple once you break it down. Thanks again.

I thought thats what conc meant and I thought you were refering to putting them back together to be YYMM format.

Report •

Ask Question