Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch Files Assistance Needed

13 views
Skip to first unread message

Jesse Josserand

unread,
Jan 21, 2003, 3:13:51 PM1/21/03
to

I need to store MMDDYYYYHHMMSS in a filename for date/time
stamping in a version history directory operation. I need
to do this by creating a variable in a batch file.

For instance.
%myfile=jfj.txt
%dtstamp=`whatever code generates MMDDYYYYHHMMSS` (what
code will do this?)
%newfilename=%myfile appended with $dtstamp (how?)
move %myfile %newfilename

Dean Wells

unread,
Jan 21, 2003, 3:40:01 PM1/21/03
to
[SCRIPT]

for /f "tokens=2-7 delims=/:. " %%a in ("%DATE% %TIME%") do (
set DATETIME=%%a%%b%%c%%d%%e%%f
)
echo %DATETIME%

[/SCRIPT]

HTH

Dean

--
Dean Wells [MVP / Windows platform]
MSEtechnology
dwe...@msetechnology.com
[[ Please respond to the Newsgroup only ]]


"Jesse Josserand" <jjoss...@eprod.com> wrote in message
news:029001c2c189$9d448930$d4f82ecf@TK2MSFTNGXA11...

Ritchie

unread,
Jan 21, 2003, 4:06:50 PM1/21/03
to
"Jesse Josserand" <jjoss...@eprod.com> wrote in message news:029001c2c189$9d448930$d4f82ecf@TK2MSFTNGXA11...
>

Use something like this to get the date/time as it'll work on NT/2K/XP
and is fairly tolerent of the current date/time regional settings:-

========================= start =========================================
echo off&setlocal
call :GetDate yy mm dd
call :GetTime hh nn ss tt
echo/Date and time is: %mm%%dd%%yy%%hh%%nn%%ss%
echo/As for the rest of what you want to do, I'm sure
echo/you'll work it out.
goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDate yy mm dd
setlocal ENABLEEXTENSIONS
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetTime hh nn ss tt
setlocal ENABLEEXTENSIONS
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
if 1%hh% LSS 20 set hh=0%hh%
endlocal&set %1=%hh%&set %2=%nn%&set %3=%ss%&set %4=%cs%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

========================= end =========================================

--
Ritchie


Dean Wells

unread,
Jan 21, 2003, 3:56:24 PM1/21/03
to

I inadvertently neglected your 2nd question -

[SCRIPT]

set MYFILE=jfi.txt


for /f "tokens=2-7 delims=/:. " %%a in ("%DATE% %TIME%") do (

set NEWFILE=%%a%%b%%c%%d%%e%%f
)
for %%V in ("%MYFILE%") do (
set NEWFILE=%%~nV%NEWFILE%%%~xV
)
echo %NEWFILE%

[/SCRIPT]

Dean

--
Dean Wells [MVP / Windows platform]
MSEtechnology
dwe...@msetechnology.com
[[ Please respond to the Newsgroup only ]]


"Dean Wells" <dwe...@mask.msetechnology.com> wrote in message
news:O3Cj70YwCHA.2640@TK2MSFTNGP11...

Jonathan de Boyne Pollard

unread,
Mar 14, 2003, 4:38:06 PM3/14/03
to
0 new messages