PDA

View Full Version : Batch file to insert date



Spartacus
11-08-2004, 04:07 PM
I read somewhere about a substitution you could use in a batch file for inserting the date (or various other entities) into a file name for example. Now that I need that functionality, I can't remember where to find it...

Specifically, I would like to run a batch file that creates a directory whose name is the current date and time, and then copies three folders into the new directory.

Any ideas appreciated!
S

Earnie Moore
11-08-2004, 06:31 PM
--- option 1 ------
make a txt file and put in
date > date.txt

close it and change the name from what ever to date.bat

this will replace the date inside the file each time to click onto date.bat


--- option 2 ------
make a txt file and put in
date >> date.txt

close it and change the name from what ever to date.bat

this will replace the date inside the file each time to click onto date.bat






PROBLEM:
There is just one problem it will stop and ask you for a new date, not sure how you could fix that

Mike
11-08-2004, 07:35 PM
>> From: 43S,172E

So where are you Spartucus? I figure you're somewhere in the middle of the South Island?

http://www.mapquest.co.uk/cgi-bin/ia_find?link=btwn/twn-map_results&zoom_level=5&uid=u13d1bs512a5o9ta:25dwaluabs&SNVData=3mad3-q.fy%28%3drxu672%3dutlu672%24tw2%28%3a%28_%3d%3a%2 8.qa72u6%28n0072u6%28l%241w-u.wf7%3bxcx5sf7.grfe%7cs%24jdvnd%7cC2j%2fCw8%2bFj7 cyv,%2b.qa%2b2%2b6%24%2b%2butl%2b6%2b2&pcat=]I hope this link works[/url] :D

Mike.

Mike
11-08-2004, 07:52 PM
Somehow you need to tell your PC (maybe in the OS somewhere) to format the date with '-' rather than '/' (eg 11-08-2004 rather than 11/08/2004)

then this would work:
set %date%=date
md %date%

I'll keep looking.

Mike.

Mike
11-08-2004, 07:57 PM
> Somehow you need to tell your PC (maybe in the OS
> somewhere) to format the date with '-' rather than
> '/' (eg 11-08-2004 rather than 11/08/2004)

The same would apply for time, but in the case of the colons rather than slashes.

Mike.

Mike
11-08-2004, 08:03 PM
> > Somehow you need to tell your PC (maybe in the OS
> > somewhere) to format the date with '-' rather than
> > '/' (eg 11-08-2004 rather than 11/08/2004)
>
> The same would apply for time, but in the case of the
> colons rather than slashes.

If you're running this batch file from within Windows, change your regional settings to display the date and/or time differently, and this batch file should work (did for me)
set %date%=date
md "%date%"
cd "%date%"

The quotes are important.

Mike.

Spartacus
12-08-2004, 09:10 AM
>> From: 43S,172E

>So where are you Spartucus? I figure you're somewhere in the middle of the
>South Island?

Close enough - must have been my rounding! :D It's Chch

I appreciate your efforts re the batch file - I'd prefer to not have to change the display settings (it's not going onto my pc), but it's given me a good starting point. I'll just have to concoct a little parsing code to change the /'s to something more acceptable.

Thanks again,
S

Spartacus
12-08-2004, 10:16 AM
Got it! (he says excitedly) - it now creates a directory such as

2004-08-12 10h14m25

depending of course on the current date and time. Code as follows:

@ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%a IN ("%date%") DO SET dd=%%a&SET mm=%%b&SET yy=%%c
FOR /F "TOKENS=1-3 DELIMS=:." %%a IN ("%time%") DO SET hh=%%a&SET tt=%%b&SET ss=%%c
MD "%yy%-%mm%-%dd% %hh%h%tt%m%ss%"

Graham L
12-08-2004, 01:12 PM
Now set it to music so you can sing it. :D