|
Answer» My question is as follows:
I need to read the date and put it in a variable, I know that: set varDate=%DATE% will work on my XP machine, but this returns: FRI 12/30/2011.
I need the date to read: 123011
Can I do have DOS change the output format? If not, I would be fine with putting 123011 in a text file and have my .bat read that, but I don't know the syntax for reading ANOTHER file!
BTW, the reason I would change the date in a text file and not my .bat is that I have MULTIPULE .bat's that I run daily and would rather change today's date in one place!This batch file will put the date in a file, but with a four digit year. For a two digit year I need to know your Windows version.
Code: [Select] @echo off for /f "tokens=6-8 delims=^/ " %%a in ('echo. ^| date') do ( echo %%a%%b%%c > date.txt )
Get back to us. I'm on XP (as stated above )
Now, this code will export to a text file? Will it be in the 123011 format (mmddyy)? If so, couldn't I just have that code in my .bat and not in an external text file (that was my "Plan B")?
THANKS!!I guessed I missed the part about XP.
Code: [Select] @echo off set mydate=%date:~4,2%%date:~7,2%%date:~12,2%
This should work nicely on XP and yes, you can include this code in your batch files instead of outputing to a file.
Hope this helps.
That was amazing! It workes like a charm!!!!!!!!!!!!!!
Now, could you explain it?!Explain it? I could barely type it!
As you noted %date% resolves to this format: Fri 12/30/2011 (is it really the year 11; where does the time GO?) Anyway, now that you have a string you can pick out the pieces you need. Using each character's offset (offset starts at zero, position starts at one), you find the month at offset 4 with a length of 2 characters, day at offset 7 for a length of 2 characters, and last 2 digits of the year at offset 12 with a length of 2 characters.
When all the pieces you've extracted are concatenated you end up with mmddyy.
Do not try this on Win9x machines.
Hope this helps.
|