Date & Time Format

D

Daniel

Hello Everyone,

I have a small problem. I have a batch that has the following:
-------Start---------

set zdate=%date:~4%
set zdate=%zdate:/=%
set ztime=%time::=%
set ztime=%ztime:~0,6%

copy c:\TestText.txt C:\%zdate%%ztime%.txt

-----------End-----------

The batch runs great except if it is ran before 10:00 and the time has a
single digit hour then it puts a SPACE between the date and time in the text
name. This causes problems and I need to find a way to either not have the
space or put a zero before the hour.

Any help is greatly appreciated.

Thanks,

Daniel
 
F

foxidrive

Hello Everyone,

I have a small problem. I have a batch that has the following:
-------Start---------

set zdate=%date:~4%
set zdate=%zdate:/=%
set ztime=%time::=%

Add this:

set ztime=%time :0=%
set ztime=%ztime:~0,6%

copy c:\TestText.txt C:\%zdate%%ztime%.txt

-----------End-----------

The batch runs great except if it is ran before 10:00 and the time has a
single digit hour then it puts a SPACE between the date and time in the text
name. This causes problems and I need to find a way to either not have the
space or put a zero before the hour.

It'll do the latter.
 
T

Timo Salmi

Daniel said:
The batch runs great except if it is ran before 10:00 and the time
has a single digit hour then it puts a SPACE between the date and
time in the text name. This causes problems and I need to find a
way to either not have the space or put a zero before the hour.

:: See to it that days 1-9 will always have a leading zero
set dd_=0%dd_%
set dd_=%dd_:~-2%

More fully in
163586 May 1 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

All the best, Timo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top