Computing.Net > Forums > Programming > batch file

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 file

Reply to Message Icon

Name: graphica
Date: February 6, 2006 at 17:03:13 Pacific
OS: win xp
CPU/Ram: Intel 1.5Ghz
Comment:

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 ?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: February 6, 2006 at 22:19:55 Pacific
Reply:

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


0

Response Number 2
Name: tekhead009
Date: February 7, 2006 at 07:24:38 Pacific
Reply:

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 = YYYYMMDD

set sDate=%DATE:~10,4%
set sDate=%sDate%%DATE:~4,2%
set sDate=%sDate%%DATE:~7,2%


0

Response Number 3
Name: FishMonger
Date: February 7, 2006 at 08:05:45 Pacific
Reply:

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%


0

Response Number 4
Name: IVO
Date: February 7, 2006 at 12:20:07 Pacific
Reply:

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.


0

Response Number 5
Name: tekhead009
Date: February 7, 2006 at 20:31:58 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: February 7, 2006 at 21:22:24 Pacific
Reply:

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


0

Response Number 7
Name: graphica
Date: February 11, 2006 at 12:12:42 Pacific
Reply:

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


0

Response Number 8
Name: graphica
Date: February 13, 2006 at 09:55:48 Pacific
Reply:

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/2006

I would be interested to see how it's done in XP


0

Response Number 9
Name: Mechanix2Go
Date: February 13, 2006 at 12:12:11 Pacific
Reply:

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


0

Response Number 10
Name: graphica
Date: February 13, 2006 at 16:32:01 Pacific
Reply:

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



0

Response Number 11
Name: Mechanix2Go
Date: February 13, 2006 at 21:40:34 Pacific
Reply:

%DATE:~10,4%

Says to skip the first 10 chars and use the next 4.

XP commands


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

M2


0

Response Number 12
Name: graphica
Date: February 14, 2006 at 05:35:19 Pacific
Reply:

M2, thanks for the explanation


0

Response Number 13
Name: Ananthaisin
Date: March 13, 2006 at 02:47:38 Pacific
Reply:

Pls tell me how do i append the same while i am getting any file from FTP.


Rgds
Anantha


0

Response Number 14
Name: Mechanix2Go
Date: March 13, 2006 at 03:43:34 Pacific
Reply:

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


0

Response Number 15
Name: Ananthaisin
Date: March 13, 2006 at 23:59:59 Pacific
Reply:

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
ha

see there in that place i have to enter date i need to format system date to that way.


Rgds
Anantha


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch file

Batch file to count a specific character in a www.computing.net/answers/programming/batch-file-to-count-a-specific-character-in-a/19751.html

FTP batch file www.computing.net/answers/programming/ftp-batch-file/9027.html

Simple (I hope) batch file problem www.computing.net/answers/programming/simple-i-hope-batch-file-problem/12736.html