Discussion Locked

How to get current date in cmd.exe.

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi All,

In Cmd.exe, I want to rename a file that names NAME.txt to NAMEddmmyy.txt where ddmmyy is current system date.

Please help in urgent!!!

4 replies

by lmon

All you have to do is rename the folder by typing the correct command. Make sure you you are in the correct directory.

If you name.txt document is in c:\documents and settings\shared then you must be in the directory before you can rename it. Navigate there by doing cd c:\documents and settings\shared hit enter then type ren name.txt name092604.txt

Ren is the command for rename.

For commands go to the link below:

http://home7.inet.tele.dk/batfiles/msdos7/

by ozi eagle

Hi,
I have written a small .exe program that creates the date and "forwards" it to a batch file for use.
The date is actually in the format yymmdd, as I have found that many files dated in this way are much easier to sort and find than by ddmmyy. If you wish a copy, post a comment or reply to this question, and I will forward to your email address.

NOTE: that if you use cmd.com then you are in MSDOS mode and your file name length may be limited to eight characters. Check ways of using long files names in MSDOS.

by rindi1

You can create a variable, like "filename". First open cmd.exe

Now enter

date

if you get an answer similar to:
The current date is: 27.09.2004

(the european system), enter

set filename=%date:~0,2%%date:~3,2%%date:~8,2%

the first number means where to begin "place" in the date string, the number after the comma tells cmd how many digits after the first number should be taken.

0,2 means get 2 numbers from place 0 =27
3,2 means get 2 numbers from place 3 =09
and 8,2 means get 2 numbers from place 8 =04

all of these numbers put together give you 270904

If you PC is set to US format (mm.dd.yy) then you just need to start off with 3,2 then 0,2 and then 8,2.

After that you can check the variable by typing
set filename

you should receive the following answer:
filename=ddmmyy

Now type

ren name.txt name%filename%.txt

and you should have the filename in the format you need. you can of course put that in a batch file to automate things, or you can do the same with TIME, if you need more details in the filename.

by doyle.jack

I have a little .exe called showclok.exe that you can run that will allow you to create variables in your .bat or .cmd file for the date parts.

I can email the .exe to you if you would like. Just let me know.

This discussion is closed to new replies.