How to %time% in a filename?

  • Thread starter Thread starter Thomas Karer
  • Start date Start date
T

Thomas Karer

I´m doing some backup jobs using %date%, now i need something like
x:\backup\%date%_%time%

This does not work because %time% says:16:33:13,03
and i only want to have hh:mm:ss from the actual system time.

thank you
tom
 
Thomas said:
I´m doing some backup jobs using %date%, now i need something like
x:\backup\%date%_%time%

This does not work because %time% says:16:33:13,03
and i only want to have hh:mm:ss from the actual system time.
is the wrong group, append .nt -)

You've got another problem, the colon is only valid to sperate the
drive letter or a data stream, sot they have to be removed.

set DateTime
set now=%date% %time%
for /f "tokens=1-8 delims=_.-:/ " %%A in ("%now%"
do set DateTime=%%A%-%%B-%%C-%%D_%%E%%F%%G%%H
echo %now%
echo %DateTime%

To fit with your local date time formats you may have to reaarange
the vars in the set command.

HTH
 
You've got another problem, the colon is only valid to sperate the
drive letter or a data stream, sot they have to be removed.
thank you for the fast response!
set DateTime
set now=%date% %time%
for /f "tokens=1-8 delims=_,-:/ " %%A in ("%now%"
do set DateTime=%%A%-%%B-%%C-%%D_%%E%%F%%G%%H
echo %now%
echo %DateTime%
hmm, i get the error message "DateTime" is not defined
To fit with your local date time formats you may have to reaarange
the vars in the set command.
sorry, i don?t understand this i played with replacing the "," at delims but
it did?nt work.

thank you
tom
 
I´m doing some backup jobs using %date%, now i need something like
x:\backup\%date%_%time%

This does not work because %time% says:16:33:13,03
and i only want to have hh:mm:ss from the actual system time.

thank you
tom
Using Today.bat from tip 8600 in the 'Tips & Tricks' at http://www.jsiinc.com
and WhatTime.bat from tip 8187:

call today MMn DDn YYn Abrev MM DD
call WhatTime Hour Minute Second Hsec
set file=X:\backup\%YYn%%MM%%DD%%Hour%%Minute%%Second%.bkf


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
sorry there is a missing closing parenthes.
hmm, i get the error message "DateTime" is not defined


sorry, i don?t understand this i played with replacing the "," at delims but
it did?nt work.


::DateTime.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off&setlocal
set now=%date% %time%
for /f "tokens=1-8 delims=,.-:/ " %%A in ("%now%"
) do set DateTime=%%A-%%B-%%C-%%D_%%E%%F%%G%%H
echo %now%
echo %DateTime%
::DateTime.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH
 
I´m doing some backup jobs using %date%, now i need something like
x:\backup\%date%_%time%

This does not work because %time% says:16:33:13,03
and i only want to have hh:mm:ss from the actual system time.

thank you
tom


XSET (shareware) will so the job http://xset.tripod.com

XSET CUR-DATE DATE YYYYMMDD
XSET CUR-TIME DATE hh-mm
MD Q:\Backup\%cur-date%_%cur-time%


Mind you, I have 98SE, but XSET can be used on XP, also you
would want to probably use the dash to separate the HHMMSS,
as the colon is for the Drive letter.

--

Sincerely, | NOTE: Best viewed in a fixed pitch font
| (©) (©)
Andrew H. Carter | ------ooo--(_)--ooo------
d(-_-)b | /// \\\
 
JRS: In article <[email protected]>, dated Sun, 30 Jan
2005 16:34:27, seen in Thomas Karer
I´m doing some backup jobs using %date%, now i need something like
x:\backup\%date%_%time%

Therefore, you should not have posted to a.m.b, but to a.m.b.nt.
This does not work because %time% says:16:33:13,03
and i only want to have hh:mm:ss from the actual system time.

NOWMINUS, via sig line 3, can output date and/or time in any reasonable
order, and can be used to set an environment variable, directly or
indirectly. It can also handle common date/time calculations, such as
setting the first day of the current week.
 
And
107597 Jun 2 2004 ftp://garbo.uwasa.fi/pc/envutil/xset549.zip
xset549.zip Put ANYTHING in environment variable, M.Stern

All the best, Timo

Hmmm. I tried it the way the poster wanted with the colons
and got an unable to create directory, then changed the
colons to dashes and the directory was created. Must be an
XP thing. 'Course I also didn't quote the output, so that
might have had something to do with it.

--

Sincerely, | NOTE: Best viewed in a fixed pitch font
| (©) (©)
Andrew H. Carter | ------ooo--(_)--ooo------
d(-_-)b | /// \\\
 
Matthias Tacke said:
::DateTime.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off&setlocal
set now=%date% %time%
for /f "tokens=1-8 delims=,.-:/ " %%A in ("%now%"
) do set DateTime=%%A-%%B-%%C-%%D_%%E%%F%%G%%H
echo %now%
echo %DateTime%
::DateTime.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
thanks!

this works great!
cu
tom
 
Back
Top