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

how to create filename with date and time from batch file then append to it

186 views
Skip to first unread message

ZenWolf

unread,
Nov 1, 2006, 5:09:09 PM11/1/06
to
Hi All,
I have a batch file that does multiple tasks and appends them to a text
file for final results. I was wondering what I need to add to the batch
file that will first create a text file with the data and time as part
of the name and then have each of the tasks append to that file. This
batch file will be run throught out the day and week and want to be
able to see the different files created. I would like the file name to
be something like testresults.MMDDYY.HHMM.txt

Thanks in advance for help,
ZenWolf

Matt Williamson

unread,
Nov 1, 2006, 6:29:13 PM11/1/06
to

This is how I would do it

@echo off
setlocal

call :GetDate y m d
call :Gettime h n s
set yfn=Testresults.%m%%d%%y%.%h%%n%.txt
Echo Task1 output>>%yfn%
Echo Task2 output>>%yfn%
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


billious

unread,
Nov 1, 2006, 8:15:09 PM11/1/06
to

"Matt Williamson" <ih8...@spamsux.org> wrote in message
news:1budnR2YdqEjsNTY...@adelphia.com...

Hmm. That must be untested, Matt.

Since you're calling GETTIME with only THREE parameters, the "set %4=%cs%"
will fail.

You can fix it as follows:

----- batch begins -------
[1]@echo off
[2]setlocal
[3]
[4]call :GetDate y m d
[5]call :Gettime h n s
[6]set yfn=Testresults.%m%%d%%y%.%h%%n%.txt
[7]Echo %yfn%
[8]call :Gettime h n s K
[9]set yfn=Testresults.%m%%d%%y%.%h%%n%.txt
[10]Echo %yfn% + %K%
[11]goto :EOF
[12]
[13]:GetDate yy mm dd
[14]setlocal ENABLEEXTENSIONS
[15]set t=2&if "%date%z" LSS "A" set t=1
[16]for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
[17] for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
[18] set %%a=%%d&set %%b=%%e&set %%c=%%f))
[19]endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
[20]
[21]:GetTime hh nn ss tt
[22]setlocal ENABLEEXTENSIONS
[23]set p4=%4&if [%4]==[] set p4=%1
[24]for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
[25] set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
[26]if 1%hh% LSS 20 set hh=0%hh%
[27]endlocal&set %p4%=%cs%&set %1=%hh%&set %2=%nn%&set %3=%ss%&goto :EOF
------ batch ends --------

This sets %4 to %cs% IF %4 was specified, otherwise it substitutes "set
%1=%cs%"

OP: It's normal to establish filenames as (CC)YYMMDDHHMMSS as the date/time
part since this is a universal format that is amenable to simple alphabetic
sorting. Your choice.


foxidrive

unread,
Nov 1, 2006, 8:51:17 PM11/1/06
to

Here's a WSH solution.

:: datetime.bat ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: This uses Windows Scripting Host
:: to set variables to the current date/time
:: for Win9x/ME/NT/W2K/XP
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
set amp=&
if not "%amp%"=="&" set amp=^^^&
set TmpFile="%temp%.\tmp.vbs"
>%TmpFile% echo n=now
>>%TmpFile% echo 'Extract the date and time strings into d and t
>>%TmpFile% echo s=Instr(1,n," ")
>>%TmpFile% echo d=left(n,s-1)
>>%TmpFile% echo t=mid(n,s+1,8)
>>%TmpFile% echo 'Create time t variable in hhmmss format
>>%TmpFile% echo 'The following line ensure leading zeros
>>%TmpFile% echo t=((Hour(t)+100)*100+Minute(t))*100+Second(t)
>>%TmpFile% echo t=right(t,6)
>>%TmpFile% echo 'extract hour, minute, second variables
>>%TmpFile% echo h=left(t,2)
>>%TmpFile% echo m=mid(t,3,2)
>>%TmpFile% echo s=right(t,2)
>>%TmpFile% echo 'Create date d variable in yyyymmdd format
>>%TmpFile% echo 'The following line ensure leading zeros
>>%TmpFile% echo d=(Year(d)*100+Month(d))*100+Day(d)
>>%TmpFile% echo 'extract year, month, day variables
>>%TmpFile% echo y=left(d,4)
>>%TmpFile% echo r=mid(d,3,2)
>>%TmpFile% echo m=mid(d,5,2)
>>%TmpFile% echo d=right(d,2)
>>%TmpFile% echo ' get the day of week
>>%TmpFile% echo dow=WeekDayName(Weekday(Date),true)
>>%TmpFile% echo WScript.Echo "set hour=" %amp% h
>>%TmpFile% echo WScript.Echo "set min=" %amp% m
>>%TmpFile% echo WScript.Echo "set sec=" %amp% s
>>%TmpFile% echo WScript.Echo "set year=" %amp% y
>>%TmpFile% echo WScript.Echo "set yr=" %amp% r
>>%TmpFile% echo WScript.Echo "set month=" %amp% m
>>%TmpFile% echo WScript.Echo "set day=" %amp% d
>>%TmpFile% echo WScript.Echo "set dow=" %amp% dow
cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
call "%temp%.\tmp.bat"
del "%temp%.\tmp.bat"
del %TmpFile%
set TmpFile=
set amp=

echo The year (YYyy) is "%year%"
echo The year (yy) is "%yr%"
echo The month is "%month%"
echo The day (%dow%) is "%day%"
echo.
echo The hour is "%hour%"
echo The minute is "%min%"
echo The second is "%sec%"
echo.

set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%

echo The date and time stamp is "%stamp%"
echo.
echo time (hhmmss) (%hour%%min%%sec%)
echo.
echo date A (yyyymmdd) (%year%%month%%day%)
echo date B (mmddyyyy) (%month%%day%%year%)
echo date C (ddmmyyyy) (%day%%month%%year%)
echo.
echo date D [yymmdd] [%yr%%month%%day%]
echo date E [mmddyy] [%month%%day%%yr%]
echo date F [ddmmyy] [%day%%month%%yr%]
:: datetime.bat ::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Eman

unread,
Nov 2, 2006, 2:25:20 AM11/2/06
to
--
for /f "tokens=*" %%a in ('HLDate "MMDDYY\.HHMM"') do (
set MyFile=testresults.%%a.txt
)
echo MyOutput>> %MyFile%
--

This would be independent on specific %date% format for
current locale.

HLDate utility is available at:
http://www.verzend.be/v/3747744/HLDate_1.0.0.zip.html

--

"ZenWolf" <zenwo...@aol.com> сообщил/сообщила в новостях следующее:
news:1162418949....@m73g2000cwd.googlegroups.com...

Matt Williamson

unread,
Nov 2, 2006, 7:54:38 AM11/2/06
to
> Hmm. That must be untested, Matt.
>
> Since you're calling GETTIME with only THREE parameters, the "set %4=%cs%"
> will fail.

It works fine on my machine. I generally don't post untested code and if I
do, I say it's untested. I understand what you're saying and appreciate the
input though. The getdate and gettime routines are Ritchie Lawrence's, I
just use them a lot because they're region setting independant and work on
all the OS's I script for. If I only want the hours and minutes, isn't it
ok to only specify the first three params and only use 2? The OP only asked
for MMDDYY.HHMM and that's what it produces on my XP Pro sp2 machine.


billious

unread,
Nov 2, 2006, 8:32:40 AM11/2/06
to

"Matt Williamson" <ih8...@spamsux.org> wrote in message
news:7-WdnSJjnakfd9TY...@adelphia.com...

I'd suggest you test it again, Matt.

Here's a stripped-down version.

It's the original routine you posted, minus the date-processing part and
simply showing the generated filename


----- batch begins -------
[1]@echo off
[2]setlocal

[3]call :Gettime h n s
[4]set yfn=Testresults.%h%%n%.txt
[5]ECHO %yfn%
[6]goto :EOF
[7]
[8]:GetTime hh nn ss tt
[9]setlocal ENABLEEXTENSIONS
[10]for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
[11] set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
[12]if 1%hh% LSS 20 set hh=0%hh%
[13]endlocal&set %1=%hh%&set %2=%nn%&set %3=%ss%&set %4=%cs%&goto :EOF
------ batch ends --------

The issue is not supplying 3 parameters and using 2.

The issue is that the gettime routine REQUIRES 4 parameters and is supplied
with only 3.

If you supply only 3 parameters as you have in line [3] then line [13] will
be evaluated to

[13]endlocal&set H=%hh%&set N=%nn%&set S=%ss%&set =%cs%&goto :EOF

now what is it that is being set to %cs%?

"set =%cs%"

will generate an error message "The syntax of the command is incorrect"

IF you supply a fourth parameter, [13] becomes

[13]endlocal&set H=%hh%&set N=%nn%&set S=%ss%&set FOURTH_PARAMETER=%cs%&goto
:EOF

so the routine works.

The mods I suggested would make gettime work whether it was supplied with 3
or 4 parameters.

It's possible -but probably silly - to extend this to two or even one
parameter.

In your applications, you're probably supplying 4 parameters. Supplying only
3 will produce an error message - and I'm surprised that you didn't see that
message when you tested the routine.

Meanwhile, on the universality front, I'd question the DELIMS set of COLON,
DOT and SPACE. I believe that COMMA should also be included as it's used as
the separator between the seconds and hundredths in some locales.


Eman

unread,
Nov 2, 2006, 8:54:25 AM11/2/06
to
"billious" <billio...@hotmail.com> сообщил/сообщила в новостях следующее:
news:4549f125$0$11302$a82e...@reader.athenanews.com...

>
> "Matt Williamson" <ih8...@spamsux.org> wrote in message

[..]

> Meanwhile, on the universality front, I'd question the DELIMS set of COLON,
> DOT and SPACE. I believe that COMMA should also be included as it's used as
> the separator between the seconds and hundredths in some locales.

You're right in your belief in comma.

Also, due to the universality front, i could note again
(http://tinyurl.com/y8bm8u), the "date" command does not
output as expected under "nt authority\system" profile
on some (MUI-enabled, i suppose) systems.

Matt Williamson

unread,
Nov 2, 2006, 10:12:26 AM11/2/06
to
> I'd suggest you test it again, Matt.
>
> Here's a stripped-down version.
>
> It's the original routine you posted, minus the date-processing part and
> simply showing the generated filename

You're right, I tested it again and put a pause before the goto: eof and it
does show a syntax error. The file does get created as expected though so I
just stopped there. I guess the simple fix would be to just supply all the
params and only use the ones necessary.


ZenWolf

unread,
Nov 2, 2006, 2:11:28 PM11/2/06
to
I would like to thank everyone for their help. I was able to use the
suggestions and able to get the results needed.


I have another question, about adding a timer to the batch file. It is
somewhat long and would like to put in a timer that starts when the
tasks begin and stop when the all the tasks are completed. It would
then write to the end of the file we just created with the amount of
time it took to run the complete list of tasks.

Thanks again,
ZenWolf

Timo Salmi

unread,
Nov 2, 2006, 3:07:46 PM11/2/06
to
ZenWolf <zenwo...@aol.com> wrote:
> I have another question, about adding a timer to the batch file. It is
> somewhat long and would like to put in a timer that starts when the
> tasks begin and stop when the all the tasks are completed. It would
> then write to the end of the file we just created with the amount of
> time it took to run the complete list of tasks.

30} Can one calculate the difference between two times in a script?
179284 Oct 21 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

Getting the (date and) time are covered in
1} How to get today's date elements into environment variables?

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

forhom...@comcast.net

unread,
Nov 2, 2006, 3:44:52 PM11/2/06
to

Try this, both renames need to be run back to back in this order Rename
1 , Rename 2

On DOS Command line type Date to see how we are counting. Start with
first letter of day of week and that is 0 (zero) Thu 11/02/2006
T=0,h=1,u=2,sp=3,etc.
In this example we are starting at pos 4 and taking next two (2) chars.
= 11

Rename 1:
ren c:\yourfilename.txt
yourfilename-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.txt

Rename 2:
ren c:\yourfilename.txt
yourfilename-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~1,1%h%time:~3,2%m%time:~6,2%s%.txt

note: time:~0,2%h in Rename 1 vs ~1,1%h in Rename 2
we are parsing thru the time that is displayed and starting at 0 and
getting hour.

rename is run down twice depending on "time of day" bat file is run,
time will display as
"space+digit" until a two digit hour is reached. A "space" is an
invalid file name and ren will not work the other will. If first rename
was completed ok, the 2nd rename will not work, as your original file
is already renamed. If the first did not complete ok as hour had a
space in it, the 2nd rename will work.

I would not reverse the order you run these as you may not get correct
results.

yourfilename-11-02-2006_@_14h31m24s is what it will look like when
done

billious

unread,
Nov 2, 2006, 10:20:37 PM11/2/06
to

"ZenWolf" <zenwo...@aol.com> wrote in message
news:1162494688.1...@h54g2000cwb.googlegroups.com...

>I would like to thank everyone for their help. I was able to use the
> suggestions and able to get the results needed.
>
>
> I have another question, about adding a timer to the batch file. It is
> somewhat long and would like to put in a timer that starts when the
> tasks begin and stop when the all the tasks are completed. It would
> then write to the end of the file we just created with the amount of
> time it took to run the complete list of tasks.
>
> Thanks again,
> ZenWolf
>

Timo's elapsed-time calculation is the way to go.

However, we have a couple of matters of protocol.

First is top-posting. Fine for emails, but not on usenet because it causes a
discussion to become hard to follow - scrool up to a following point, then
down to read it.

Also, some correspondents who have tired of repeatedly pointing out the
protocol will ignore threads that don't adhere to it. This reduces your
chances of getting useful replies.

Second matter is raising an unrelated point in any thread - especially a
resolved thread. Two reasons - on the chance that people actually read the
history before raising FAQ#37 again, your new point and its resolution will
be missed and yet another thread will appear. And second, once a problem has
been resolved, many will ignore a continued discussion on the assumption
that it's one of the boring flame-wars that some correspondents insist on
generating over academic points and opinions.

It costs no more to start a new thread with a relevant title.


Eman

unread,
Nov 3, 2006, 10:31:50 AM11/3/06
to
"Matt Williamson" <ih8...@spamsux.org> сообщил/сообщила в новостях следующее:
news:7-WdnSJjnakfd9TY...@adelphia.com...

>> Hmm. That must be untested, Matt.
>>
>> Since you're calling GETTIME with only THREE parameters, the "set %4=%cs%"
>> will fail.
>
> It works fine on my machine. I generally don't post untested code and if I do,
> I say it's untested. I understand what you're saying and appreciate the input
> though. The getdate and gettime routines are Ritchie Lawrence's, I just use
> them a lot because they're region setting independant and work on

I do not know who first name it to be "region setting
independent" (i saw quite a lot batch script examples
of such type), but that's simply not true.
I don't think it was initially a false representation,
but maybe just a misunderstanding. That's not only
because of the COMMA.

> :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

Here we're assuming that we always get "yy", "mm" and
"dd" in some (locale-dependent order) from the second
line of date' output. However, that's true only for
[most of] locales with Latin-based alphabet. Just try
it under some Cyrillic, Arabic, or Greek etc. locale
and we'll see that %yy%, %mm% and %dd% are empty.
Nevertheless, we could be able to read iDate value
from the registry, but there're no guaranty these key
and value will be the same in a future versions of OS.

Actually, one has to come to conclusion that there are
no standard WinNT' command-line facilities to determine
current date in locale-independent matter using *pure*
batch-scripting technique so that it would be both
locale-independent and reliable enough for the future.

ZenWolf

unread,
Nov 3, 2006, 11:32:08 AM11/3/06
to
Billious,
Thank you for setting me straight on the protocol of usenet. I am new
to all of this and was just trying to get help. With everyones
suggestions I have been able to resolve my current issues. I have
decided that I will not need to put a timer in the batch file, but if I
change my mind, I will create a new topic for each issue that I could
use help with.

Thanks to everyone for your support and knowledge,
ZenWolf

billious

unread,
Nov 3, 2006, 11:59:02 AM11/3/06
to

"Eman" <e!m!a!n...@hotmail.com> wrote in message
news:eifnjo$2hub$1...@news.mtu.ru...
> "Matt Williamson" <ih8...@spamsux.org> ???????/???????? ? ????????
> ?????????:

> news:7-WdnSJjnakfd9TY...@adelphia.com...
>>> Hmm. That must be untested, Matt.
>>>
>>> Since you're calling GETTIME with only THREE parameters, the "set
>>> %4=%cs%"
>>> will fail.
>>
>> It works fine on my machine. I generally don't post untested code and if
>> I do,
>> I say it's untested. I understand what you're saying and appreciate the
>> input
>> though. The getdate and gettime routines are Ritchie Lawrence's, I just
>> use
>> them a lot because they're region setting independant and work on
>

>> :GetDate yy mm dd

Sure - I agree. It's only "Universal" for English - whether it's MM-DD-YY as
used in North America or DD/MM/YY as used in the English-speaking world.

Theoretically, you could fix the "incorrect skip for some languages" problem
with

for /f "tokens=2-4 delims=(-)" %%a in ('echo/^|FIND "("^|date') do (

to isolate only the line with parentheses - assuming all languages use
parentheses of course.

The other problem is that all we have is three symbols that can be derived,
and no indication of the meaning of those symbols.

Theoretically, you could try
1 Get the digits from the DATE command
2 Set the date to "13/01/13"
3 Get the digits again and see if they've changed. If not - MMDDYY format &
done
4 Set the date to "32/01/28"
5 Get the digits again. If they're now "320128" then YYMMDD format, else
DDMMYY format
6 Restore the date to the original setting

Add a little bit of a delay if this manipulation is occurring at 23:59:59
(however you detect that...) to prevent resetting the date to yesterday if
midnight clicks over and you're done.

Now quite what effect that might have on other programs which may detect the
change, I'll not predict. And I recall that it might be possible for a
sysadmin to prevent date changes too.

Or possibly it's in the registry somewhere. Consult the documentation :) to
find it....

The real solution, if the MSDOS programmer has been reading the newsgroups
(ROFL), is for a /U switch for date (and possibly time also) to show

CCYYMMDD W sep1 HHMMSSHS sep2 sep3
CC - Century
YY - Year
MM - Month
DD - Day
W - Day number (0-6 or 1-7)
sep1 - date separator
HH - Hour (24-hr format)
MM - Minute
SS - Seconds
HS - Hundredths of seconds
sep2 - minutes separator
sep3 - hundredths separator

Quite frankly, I don't care what format - so long as it's fixed and no
element is variable-length.


Dr J R Stockton

unread,
Nov 3, 2006, 9:34:59 AM11/3/06
to
In message <1162500292.8...@h54g2000cwb.googlegroups.com>, Thu,
2 Nov 2006 12:44:52, "forhom...@comcast.net"
<forhom...@comcast.net> writes

>
>On DOS Command line type Date to see how we are counting. Start with
>first letter of day of week and that is 0 (zero) Thu 11/02/2006

11/02/2006 was a Saturday - 11th Feb 2006.

Writing and recommending code whose correct operation is dependent on a
user-changeable system setting is unprofessional, even in America.

The OP should use testresults_YYYYMMDD-HHMM.txt for its obvious
advantages.

NOWMINUS, via sig line 3, generates various date/time formats
independently of OS settings.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Dr J R Stockton

unread,
Nov 3, 2006, 6:34:18 PM11/3/06
to
In message <454b7359$0$11333$a82e...@reader.athenanews.com>, Sat, 4 Nov
2006 00:59:02, billious <billio...@hotmail.com> writes

>Sure - I agree. It's only "Universal" for English - whether it's MM-DD-YY as
>used in North America or DD/MM/YY as used in the English-speaking world.

Aptly put - but DD/MM/YY / DD/MM/YYYY (variously separated) is also used
throughout that part of Europe which is on the other side of the English
Channel / North Sea.

>Now quite what effect that might have on other programs which may detect the
>change, I'll not predict. And I recall that it might be possible for a
>sysadmin to prevent date changes too.

Anything up to catastrophic, except maybe in mono-programming DOS.


>The real solution, if the MSDOS programmer has been reading the newsgroups
>(ROFL), is for a /U switch for date (and possibly time also) to show
>
>CCYYMMDD W sep1 HHMMSSHS sep2 sep3
>CC - Century
>YY - Year
>MM - Month
>DD - Day
>W - Day number (0-6 or 1-7)

Not enough, since the Week starts on Monday according to ISO, but on
Sunday in the USA (where they ignore the bit in Genesis about the
seventh day).

>sep1 - date separator
>HH - Hour (24-hr format)
>MM - Minute
>SS - Seconds

Decimal point required there. Better IMHO to give space-separated CCYY
MM DD hh mm ss.sss

>HS - Hundredths of seconds
>sep2 - minutes separator
>sep3 - hundredths separator
>
>Quite frankly, I don't care what format - so long as it's fixed and no
>element is variable-length.

Any such recommendation should be to give a format rigorously compatible
with ISO 8601:2004 (preferably not using the central T, but space
instead). Add a /W option to give the ISO year-week-day numbering, and
/O to give ISO Ordinal Date. See via sig.

Your proposal needs also to cover the relationship of local time to
standard time and UTC.


The task of generating date/time formats independently of OS settings
(in any of the forms above) can easily be done in a HLL (NOWMINUS) or in
JScript or VBscript in Win32.

In JScript one can get both the local date/time and the UTC date/time,
for Standard Output.

Eman

unread,
Nov 4, 2006, 4:52:53 AM11/4/06
to
"billious" <billio...@hotmail.com> сообщил/сообщила в новостях следующее:

>> Actually, one has to come to conclusion that there are

It's possible to complicate a batch-script code for more
universality, but that would be "against the nature" of
scripting, i think. That's why i've stepped forth here
with the separate utility for that purpose. The known ones
like Stephen Ferg's fdate and what Dr J R Stockton recommend
here could also be used, but what i don't like in them is,
16-bitness, that can bring to some undesirable side effects
under WinNT, and quite tangled set of command-line options
(not so easy to remember).

Tika

unread,
Nov 4, 2006, 7:35:03 AM11/4/06
to
Eman wrote:
> It's possible to complicate a batch-script code for more
> universality, but that would be "against the nature" of
> scripting, i think. That's why i've stepped forth here
> with the separate utility for that purpose. The known ones
> like Stephen Ferg's fdate and what Dr J R Stockton recommend
> here could also be used, but what i don't like in them is,
> 16-bitness, that can bring to some undesirable side effects
> under WinNT, and quite tangled set of command-line options
> (not so easy to remember).

Doff (http://www.jfitz.com/dos/index.html) is a Win32 application, IMO
it's a must-have and should be installed in any %WINDIR%\System32 directory.

Because it comes with source code, there is no real reason why someone
would mess around with date and time in a batch file other than
something like this:

FOR /F "eol=; tokens=* delims=#" %%a in ('DOFF "yyyy-mm-dd hh:mi:ss"')
DO SET MYDATETIME=%%a

Only flaw is that the original DOFF does not listen to 'DOFF /?' but
takes 'DOFF -h' instead to display the help screen.

Another Win32 utility to retrieve the date is logtext
(http://www.logtext.de). It does not come with source code but
additionally outputs the offset to UTC.

No more than this is needed:
FOR /F "eol=; tokens=* delims=#" %%a in ('LOGTEXT STDOUT ""') DO SET
MYDATETIME=%%a

Both programs are what MS forgot to ship with NT/2000/XP.

Eman

unread,
Nov 4, 2006, 9:42:30 AM11/4/06
to
"Tika" <ti...@doesntexist.org> сообщил/сообщила в новостях следующее:

> Doff (http://www.jfitz.com/dos/index.html) is a Win32 application, IMO it's a
> must-have and should be installed in any %WINDIR%\System32 directory.
>
> Because it comes with source code, there is no real reason why someone would
> mess around with date and time in a batch file other than something like this:
>
> FOR /F "eol=; tokens=* delims=#" %%a in ('DOFF "yyyy-mm-dd hh:mi:ss"') DO SET
> MYDATETIME=%%a
>
> Only flaw is that the original DOFF does not listen to 'DOFF /?' but takes
> 'DOFF -h' instead to display the help screen.
>
> Another Win32 utility to retrieve the date is logtext (http://www.logtext.de).
> It does not come with source code but additionally outputs the offset to UTC.
>
> No more than this is needed:
> FOR /F "eol=; tokens=* delims=#" %%a in ('LOGTEXT STDOUT ""') DO SET
> MYDATETIME=%%a
>
> Both programs are what MS forgot to ship with NT/2000/XP.

Thank you for the names. These programs would be quite
difficult to find at google. That is good stuff.
However, they can't output e.g. month name (in a given
locale), or day-of-week name (ibid.) or number, or just
number of days ("since midnight 1899-12-30"). That makes
me feel that my HLDate (http://tinyurl.com/y97tyy) has
its right to live too.

Tika

unread,
Nov 4, 2006, 12:08:39 PM11/4/06
to
Eman wrote:
> However, they can't output e.g. month name (in a given
> locale), or day-of-week name (ibid.) or number, or just
> number of days ("since midnight 1899-12-30"). That makes
> me feel that my HLDate (http://tinyurl.com/y97tyy) has
> its right to live too.

Thanks. The program directly made it into my collection.

0 new messages