getting Date and time values

  • Thread starter Thread starter Cesar Garcia
  • Start date Start date
C

Cesar Garcia

hello everybody,

im doing a batch file to make backup of some sort of data with winrar.

i'm giving parameters to winrar to make .rar files with my backup compressed
data.

The problem is this : I want to put the date and time of the system in the
filename. For this i have to pass this values to the winrar in my batch
file... but i dont know hot to do it...

anoyone know how?

regards,

Cesar Garcia H.
 
Here's one way
@echo off
setlocal enableextensions
for /f "tokens=1-2" %%a in ("%DATE%") do for /f "tokens=1-3 delims=-/.," %%d
in ("%%b") do set ThisDate=%%f%%d%%e
for /f "tokens=1-4 delims=-:.," %%a in ("%TIME%") do set ThisTime=%%a%%b%%c
set ThisTime=%ThisTime: =%

echo %ThisDate% %ThisTime%

Where thisdate is YYYYMMDD
ThisTime is [H]HMMSS

Which produces output like this:
20040713 175328
So a filename could be something like
MyArchive-%ThisDate%-%ThisTime%.rar
which would look like this:
MyArchive-20040713-175328.rar

You may have to adjust the variable order in the for loops for your system
time and date format.
 
did i mention that i'm working in win 98?..

sorry!.

Paul R. Sadowski said:
Here's one way
@echo off
setlocal enableextensions
for /f "tokens=1-2" %%a in ("%DATE%") do for /f "tokens=1-3 delims=-/.," %%d
in ("%%b") do set ThisDate=%%f%%d%%e
for /f "tokens=1-4 delims=-:.," %%a in ("%TIME%") do set ThisTime=%%a%%b%%c
set ThisTime=%ThisTime: =%

echo %ThisDate% %ThisTime%

Where thisdate is YYYYMMDD
ThisTime is [H]HMMSS

Which produces output like this:
20040713 175328
So a filename could be something like
MyArchive-%ThisDate%-%ThisTime%.rar
which would look like this:
MyArchive-20040713-175328.rar

You may have to adjust the variable order in the for loops for your system
time and date format.

Cesar Garcia said:
hello everybody,

im doing a batch file to make backup of some sort of data with winrar.

i'm giving parameters to winrar to make .rar files with my backup
compressed
data.

The problem is this : I want to put the date and time of the system in the
filename. For this i have to pass this values to the winrar in my batch
file... but i dont know hot to do it...

anoyone know how?

regards,

Cesar Garcia H.
 
Cesar said:
did i mention that i'm working in win 98?..

No, you didn't...

Seeing as this is a win2000 newsgroup, you'll get cmd.exe answers here.

Try posting your question in an appropriate group, such as alt.msdos.batch.

Regards,

Bill
 
Back
Top