Question : How do you get the Date and Time into the format CCYYMMDDHHMMSS?

Very simply question.

I am using an Win32Console Zip program (ZipMagic's) to create a regular backup of a development directory.

I want to create a zip file (I can do that bit no problems) with the name containing the date and time. This would allow me to not have to move the file manually or rename it.

By using this method, I can schedule the zip every 5 minutes and have a load of backups for the few hours I work on the project. If I want to go back, I can choose when to go back to.

I can also take a copy manually by running the schedule by hand.

How can I get todays date and time into a batch file.

The batch file I want to run is ...

zipmd -a -e4 -nr -r DevCCYYMMDDhhmmss.zip dev

The seconds are not too important, so DevCCYYYMMDDhhmm.zip will do.

I can get the date and time as environment variables, but they have the / and : in them.

DOIT.BAT

@echo off
echo | more | time | Find "Current" > 01010.bat
call 01010
echo | more | date | Find "Current" > 01010.bat
call 01010

and CURRENT.BAT

@ECHO OFF
IF "%1"=="time" SET TODAYS_%1=%3
IF "%1"=="date" SET TODAYS_%1=%4

Results in ...

TODAYS_TIME=11:25:41.00
TODAYS_DATE=01/10/2001

But I don't know how to remove the / and the : from them.

Any ideas?

Regards,

Richard Quadling.

Answer : How do you get the Date and Time into the format CCYYMMDDHHMMSS?


Richard,

Here's a script that does most of it for you. Maybe you can use it "as is"
or debug it for your os and version. It gets the date and time into variables
similar to the methods you posted, then parses the strings
to remove the components mentioned.

As previously noted, this requires Choice.com ... I was testing another script
using only internal commands which works ok under DOS 7 and below.
The FOR command handles the slash delimiter differently under DOS 7
as well as certain other os/versions so you may need to alter the way I did that part.
It wouldn't be a problem on a system having the date formatted with a 'dash' separator,
but may need editing for your particular system. This portion of the script having the line:

for %%x in (/ - : [) do if "%1"=="%%x" shift

...is where I put the separators to be removed. In the above I included
the foreslash ( / ), dash ( - ) and colon ( : ) as characters to parse and eliminate.
The 'bracket' ( [ ) character needs to be there, but the other three characters
can be removed or others added. I used the For loop while I tested
parsing various characters (like the dash, which is the date separator
on the system I was testing on) because it was more convenient.
(If you include a character that doesn't exist in the string, it's just ignored.)
That For loop does the same thing as the following four lines would do:

if "%1"=="/" shift
if "%1"=="-" shift
if "%1"==":" shift
if "%1"=="[" shift

So if the For loop doesn't work for you to remove the slash (dependent on your os/ver)
then you can remove that For loop line and just add lines using the IF command
to test for the characters you need to remove.

For example, if you need to remove only the date string's slash separator
and the time string's colon separator, you can eliminate that For loop
and replace it with the IF command to test for the characters you're concerned with, like:

if "%1"=="/" shift
if "%1"==":" shift
if "%1"=="[" shift

Again, note that the bracket in the third line above is part of the script and must be used
(and placed after the line having the characters to be removed) if you don't use that For loop.

The portion that goes like this:

if "%col%"=="2" goto end
if "%col%"=="1" set col=2
if "%1"==":" set col=1

...is just a way I used to stop the parsing to leave off the seconds as you mentioned.

The results are processed to a string and assigned to the %vardt% variable.
(You can rename the variables.) You can then use that variable as needed.
The end of the script echoes the contents of the %vardt% variable to the screen
before removing and clearing the temporary files and variables.

So if the Date is 10-01-2001 and the Time is 12:38:14.65p
the script will return a string of:

100120011238

Using the examples you posted, having a Date in the format of 01/10/2001
and a Time of 11:25:41.00, the script will return a string of:

011020011125

Then just append the %vardt% variable to the Dev portion in your zip command, like:

zipmd -a -e4 -nr -r Dev%vardt%.zip dev

Hopefully this works for you and/or you can use some of it
to get the string formatted as necessary...
Post back if you want more about it.
Here's the script:


@echo off
cls
for %%x in (%dvar% %tvar%) do if not "%%x"=="" goto got
echo.|date>~rin1010.bat
echo set dvar=%%4>current.bat
call ~rin1010.bat
echo.|time>~rin1010.bat
echo set tvar=%%3>current.bat
call ~rin1010.bat
%0 %dvar%%tvar%
:got
if "%rin%"=="1010" goto quad
set rin=1010
echo ;|choice/c;%1; %0;>~rin1010.bat
~rin1010.bat
:quad
if "%col%"=="2" goto done
if "%col%"=="1" set col=2
if "%1"==":" set col=1
for %%x in (/ - : [) do if "%1"=="%%x" shift
if "%1"=="]?" goto done
set vardt=%vardt%%1
shift
goto quad
:done
echo %vardt%
for %%x in (~rin1010 current) do if exist %%x.bat del %%x.bat
set vardt=
set dvar=
set tvar=
set col=
set rin=


 
Random Solutions  
 
programming4us programming4us