creating a file with date format

  • Thread starter Thread starter Robin
  • Start date Start date
R

Robin

From a command prompt I need to create a file name with the current date
without the / separators which is then used in a batch file.

Does anybody have any sample files that do this?
 
Robin said:
From a command prompt I need to create a file name with the current date
without the / separators which is then used in a batch file.

Does anybody have any sample files that do this?

The simple way is to use something like the following. [Keeping
the commands separate like this enables you more easily to see
what the script does].

SET dd=%date:~4,2%
SET mm=%date:~7,2%
SET yy=%date:~12,2% or
SET yyyy=%date:~10,4%

These depends on your %date% giving the format Thu 15/04/2004.
Adjust if necessary.

You can then use %yy%%mm%%dd%FileName.ext

Ray
 
Robin said:
From a command prompt I need to create a file name with the current date
without the / separators which is then used in a batch file.

Does anybody have any sample files that do this?

I do it this way in a batch file:

setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%c in ("%DATE%") do set TheDate=%%d
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%c%%d%%e
echo I:\daily\%TheDate%.log

Which gives:
I:\daily\04152004.log

%%c is the month
%%d is the day
%%e is the year

You can rearrange them for thebest format for you in the set command.
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%c%%d%%e
04152004
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%e%%c%%d
20040415 (my prefered format)
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%d%%c%%e
15042004

Should be fairly simnple to localize for your settings.
 
From a command prompt I need to create a file name with the current date
without the / separators which is then used in a batch file.

Does anybody have any sample files that do this?

The Mount/\Command called ".GetLogDate" is part of the FREE Advanced
NT/2K/XP/K3 Command Library. Syntax for a COPY command would be:

%.GetLogDate%
COPY Source.log %#LogDate%.log


(http://TheSystemGuard.com/MtCmds/GetValue/GetLogDate.htm)
(http://ntlib.com)

*******
Notes:

1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.

*******

TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-coded page, highlighting the differences
among the NT/2K/XP/K3 versions. The complete help text for each OS is also
available for comparison (http://TheSystemGuard.com/TheGuardBook/CCS-Int).

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 
Back
Top