Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone know how to create a batch file that will automatically get the current date in the format year month day eg. 20060206 (using todays date as an example)
Can this be done using dos batch file programming ?

It's a peice of cake with XP.
It takes a little more doing in DOS.
I can show you how to get it done.
You need to:
ver
[enter]
echo.|date
[enter]
and post result.
If at first you don't succeed, you're about average.M2

Yes, and it so happens I have the code right here. I use it often for creating directories for backup, or logfile names..
:: - sDate will = YYYYMMDDset sDate=%DATE:~10,4%
set sDate=%sDate%%DATE:~4,2%
set sDate=%sDate%%DATE:~7,2%

tekhead009,
Why do it 3 steps when it can just as easily be done in 1?set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

Hi FishMonger and Tekhead009,
and what happens if the XP is the home edition or the country settings for date assume the format is DD/MM/YYYY as in Europe?
XP home does not store the day of week in the Date variable as Win 2000 does, so better to manipulate the substrings from right to left to achieve vcompatibility.
More, although I am an enthusiast of US, in the world there are other countries with their own behaviors.
So better to follow the tip of M2 before giving any code.

Excuse me for being a bit gung-ho. It was a first post.
IVO:
Yes, if you were to do it right, you should check the computers date format prior to parsing out the string. Please correct me if I'm over thinking it a bit, but that would involve redirecting the echo.|date output, reading the redirect, and creating branch code based on the found format. Please tell me you have an easier solution in mind!FishMonger:
Right again. It was leftover that way from when I was playing around with it. Broken down into steps.

Hi gang,
Yep, unless and until we know the language, version and layout of the alleged DOS, nothing much usefull will get done.
That's why I asked what I did in #1.
If at first you don't succeed, you're about average.M2Go

I tried Fishmongers suggestion
set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
and this provided the date in the format I requested eg 20060211
Now is there a way to reverse the format of the date so it is displayed as 11206002
thanks for all your suggestions, you guys are great

Does anyone know how to create a batch file that will automatically get the current date in the format year month day eg. 20060206 (using todays date as an example)
Can this be done using dos batch file programming ?My ver is XP 5.1.2600
date is Sat 02/11/2006I would be interested to see how it's done in XP

set myDATE=%date:~10,4%%date:~4,2%%date:~7,2%
This will only work with a date layout EXACTLY as you posted.
If at first you don't succeed, you're about average.M2

Thanks M2
can you explain this line, I tried searching for an explanation but did not have any satisfactory results
set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
as you can see I am a newbie trying to get my feet wet

%DATE:~10,4%
Says to skip the first 10 chars and use the next 4.
If at first you don't succeed, you're about average.M2

If you mean append the sdate to the filename:
ren filename.ext %sdate%filename.ext
If at first you don't succeed, you're about average.M2

o url(10.14...)
billy
billy123$
promp
lcd C:\Anna\Ann\DUMP\
cd \
pwd
bin
ha
CD ch/Wed2006-03-15(format here)/c1
mget SB_CU1.TXT
cd \
pwd
bin
hasee there in that place i have to enter date i need to format system date to that way.
Rgds
Anantha

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

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