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

tscmd41.zip Useful NT/2000/XP script tricks and tips

17 views
Skip to first unread message

Timo Salmi

unread,
Oct 20, 2006, 11:59:11 PM10/20/06
to
Sat 21-Oct-2006: I have once again updated my command-line script
FAQ collection:

179284 Oct 21 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd41.zip Useful NT/2000/XP script tricks and tips, T.Salmi

Added the alternative input option dd.mm.yyyy besides dd mm yyyy for
"DATEINFO.CMD Display date related information"
Also added a weak date locale test to DATEINFO.CMD.

Added the following new items to the FAQ file 1CMDFAQ.TXT
150} How can I extract the http and ftp URL:s from an HTML file?
151} Extract the lines of a text file from between to marker-lines?
152} How can I remove all !:s and &:s from a text file with a script?
153} How do I test if my Internet connection to an IP is working?

Added yet another option script-only to
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

Alexander Suhovey

unread,
Oct 21, 2006, 12:30:35 AM10/21/06
to
"Timo Salmi" <t...@uwasa.fi> wrote in message
news:ts200610210...@vilkku.uwasa.fi...

Timo,

If I may, a suggestion:
You tend to use "write vbs output to file > parse file with 'for'" approach
in your VBS/cmd mixed solutions. That seems suboptimal for me. You could
skip all file operations by parcing output of vbs with 'for' directly. That
will IMHO make solutions more robust and will improve performance.

Thank you for your continuous work on tscmd.zip.

--
Alexander Suhovey

Timo Salmi

unread,
Oct 21, 2006, 12:38:56 AM10/21/06
to
Alexander Suhovey <asuh...@gmail.com> wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote in message
>> 179284 Oct 21 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>> tscmd41.zip Useful NT/2000/XP script tricks and tips, T.Salmi

> If I may, a suggestion:

Yes, please.

> You tend to use "write vbs output to file > parse file with 'for'"
> approach in your VBS/cmd mixed solutions. That seems suboptimal for me.
> You could skip all file operations by parcing output of vbs with 'for'
> directly. That will IMHO make solutions more robust and will improve
> performance.

I am not sure if I quite can unravel your suggestion. Would you kindly
help further and show a simple code example to help me better understand
your welcome idea.

Alexander Suhovey

unread,
Oct 21, 2006, 1:45:31 PM10/21/06
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:4539a436$0$1131$9b53...@news.fv.fi...

> Alexander Suhovey <asuh...@gmail.com> wrote:
>> "Timo Salmi" <t...@uwasa.fi> wrote in message
>>> 179284 Oct 21 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>>> tscmd41.zip Useful NT/2000/XP script tricks and tips, T.Salmi
>
>> If I may, a suggestion:
>
> Yes, please.
>
>> You tend to use "write vbs output to file > parse file with 'for'"
>> approach in your VBS/cmd mixed solutions. That seems suboptimal for me.
>> You could skip all file operations by parcing output of vbs with 'for'
>> directly. That will IMHO make solutions more robust and will improve
>> performance.
>
> I am not sure if I quite can unravel your suggestion. Would you kindly
> help further and show a simple code example to help me better understand
> your welcome idea.

Err, seems I didn't have my coffe.

Don't know what I was thinking when I was writing this: "You tend to use
"write vbs output to file > parse file with 'for'".
Your actual algorithm of "cmd creating vbs creating another cmd" is even
more... uhm... unusual IMHO.

Anyway, it seemed obvious to me that extra file operations would be a
bottleneck from execution time standpoint (besides it being just extra code)
but that I couldn't quite confirm in my tests. I took your CMD/VBS/CMD
solution '1)' from 1CMDFAQ and removed all but create-vbs file operations
from both cmd and vbs scripts:

====================8<========================
@echo off & setlocal
set tvbs=c:\temp\tmp$$$.vbs
findstr "'%skip%VBS" "%~f0" > %tvbs%
for /f "tokens=1-6 delims= " %%i in (
'cscript /nologo %tvbs%') do (
set dd_=%%i
set mm_=%%j
set yyyy_=%%k
set hh_=%%l
set mi_=%%m
set ss_=%%n)
del %tvbs%
echo Date by %%date%% %date%
echo Time by %%time%% %time%
echo dd_=%dd_%
echo mm_=%mm_%
echo yyyy_=%yyyy_%
echo hh_=%hh_%
echo mi_=%mi_%
echo ss_=%ss_%
goto :EOF
' The Visual Basic Script
sO = Right(0 & Day(Now), 2) & " " 'VBS
sO = sO & Right(0 & Month(Now), 2) & " " 'VBS
sO = sO & Year(Now) & " " 'VBS
sO = sO & Right(0 & Hour(Now), 2) & " " 'VBS
sO = sO & Right(0 & Minute(Now), 2) & " " 'VBS
sO = sO & Right(0 & Second(Now), 2) & " " 'VBS
WScript.Echo sO 'VBS
====================8<========================

Using TIMETHIS I observed no particular improvement in execution time. It
seems that 'for /f' loop has equal impact as all file operations in original
script. That's puzzling...

I still think though that getng rid of extra code in above example was a
good idea. But that's just me.

Anyway, sorry for bothering you. Maybe at least you may find my VBS part
worthy as more clean and readable.

--
Alexander Suhovey

Alexander Suhovey

unread,
Oct 21, 2006, 3:26:48 PM10/21/06
to
What I am usually do is simply echo VBS content to file. If you replace
findstr line with following echo line in my variant:

echo WScript.Echo Right(0 ^& Day(Now), 2) ^&" "^& ^
Right(0 ^& Month(Now), 2) ^&" "^& ^
Year(Now) ^&" "^& ^
Right(0 ^& Hour(Now), 2) ^&" "^& ^
Right(0 ^& Minute(Now), 2) ^&" "^& ^
Right(0 ^& Second(Now), 2) > %tvbs%

you may see a noticeable improvement in sript speed. I had around .220 for
original and changed scripts while with this change it finishes in around
.150

This however may look like less nice and readable formatting. :-)

--
Alexander Suhovey

Timo Salmi

unread,
Oct 21, 2006, 4:09:19 PM10/21/06
to
Alexander Suhovey <asuh...@gmail.com> wrote:
> What I am usually do is simply echo VBS content to file. If you replace
> findstr line with following echo line in my variant:
>
> echo WScript.Echo Right(0 ^& Day(Now), 2) ^&" "^& ^
> Right(0 ^& Month(Now), 2) ^&" "^& ^
> Year(Now) ^&" "^& ^
> Right(0 ^& Hour(Now), 2) ^&" "^& ^
> Right(0 ^& Minute(Now), 2) ^&" "^& ^
> Right(0 ^& Second(Now), 2) > %tvbs%

That's nice, Alexander. I'll add the Google link to your posting
into my first item on dates/times as
http://www.google.com/groups?selm=ehdse8$2mr6$1%40news.mtu.ru

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

Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

J R Stockton

unread,
Oct 21, 2006, 3:22:12 PM10/21/06
to
In message <ehdmg9$2leg$1...@news.mtu.ru>, Sat, 21 Oct 2006 21:45:31,
Alexander Suhovey <asuh...@gmail.com> writes

>' The Visual Basic Script
>sO = Right(0 & Day(Now), 2) & " " 'VBS
>sO = sO & Right(0 & Month(Now), 2) & " " 'VBS
>sO = sO & Year(Now) & " " 'VBS
>sO = sO & Right(0 & Hour(Now), 2) & " " 'VBS
>sO = sO & Right(0 & Minute(Now), 2) & " " 'VBS
>sO = sO & Right(0 & Second(Now), 2) & " " 'VBS
>WScript.Echo sO 'VBS


A - on the code above.
1. Now is a comparatively expensive function so should be called only
once and the result saved, for example in N.
2. Now is dynamic, so could change between calls, so - ditto.
3. Using 100 + Day(N) *should*, but might not, be insignificantly
faster than 0 & Day(N) - likewise the others.

B - General.
1. Unfortunately, I no longer have Win98; and DOS 6.20 is elsewhere.
Some of the consequences should be obvious. Also, supporting my
Pascal programs may be harder.
2. At present, I cannot receive E-mail.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Alexander Suhovey

unread,
Oct 21, 2006, 7:14:46 PM10/21/06
to
"J R Stockton" <j...@merlyn.demon.co.uk> wrote in message
news:VgnSrEPk...@merlyn.demon.co.uk...

> 1. Now is a comparatively expensive function so should be called only
> once and the result saved, for example in N.
> 2. Now is dynamic, so could change between calls, so - ditto.

This is a classic W/T/F (http://thedailywtf.com/). How could I miss that?
Thank you for pointing out.

--
Alexander Suhovey

Timo Salmi

unread,
Oct 22, 2006, 6:06:20 AM10/22/06
to
Alexander Suhovey <> wrote:

> "J R Stockton" <j...@merlyn.demon.co.uk> wrote:
>> 1. Now is a comparatively expensive function so should be called only
>> once and the result saved, for example in N.
>> 2. Now is dynamic, so could change between calls, so - ditto.

@echo off & setlocal enableextensions
set vbs_=%temp%\tmp.vbs
echo FixedNow=Now>%vbs_%
echo WScript.Echo Right(0 ^& Day(FixedNow), 2) ^&" "^& ^
Right(0 ^& Month(FixedNow), 2) ^&" "^& ^
Year(FixedNow) ^&" "^& ^
Right(0 ^& Hour(FixedNow), 2) ^&" "^& ^
Right(0 ^& Minute(FixedNow), 2) ^&" "^& ^
Right(0 ^& Second(FixedNow), 2) >> %vbs_%
cscript //nologo %vbs_%
for %%f in (%vbs_%) do if exist %%f del %%f
endlocal & goto :EOF

The output might be e.g.
C:\_D\TEST>cmdfaq
22 10 2006 12 57 26

> This is a classic W/T/F (http://thedailywtf.com/). How could I miss
> that? Thank you for pointing out.

Although unrelated, I particularly enjoyed this tidbit:

if b = b then
b = true
end if

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

foxidrive

unread,
Oct 22, 2006, 9:02:37 AM10/22/06
to
On Sun, 22 Oct 2006 13:06:20 +0300, Timo Salmi wrote:

> The output might be e.g.
> C:\_D\TEST>cmdfaq
> 22 10 2006 12 57 26

Here's mine:

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

Dr J R Stockton

unread,
Nov 6, 2006, 6:16:50 PM11/6/06
to
In message <ts200610210...@vilkku.uwasa.fi>, Sat, 21 Oct 2006
06:59:11, Timo Salmi <t...@uwasa.fi> writes

>Sat 21-Oct-2006: I have once again updated my command-line script FAQ
>collection:
>
> 179284 Oct 21 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
> tscmd41.zip Useful NT/2000/XP script tricks and tips, T.Salmi

That contains the almost-new
Subject: 149) How to calculate a date's week number with a pure cmd
script?

That looks like the ISO 8601 number, in which case it is necessary to
get also the Year Number. 2006-01-01 = 2005-W52-7. But your code gives
me 53, so I don't know what sort of Week Number you're calculating - or
is it just a bug?

25.12.2005 Week number 51 // Sun
31.12.2005 Week number 52 // Sat
01.01.2006 Week number 53 // Sun ??!!??

The algorithm of JDweekNumber looks over-long (though I don't follow it)
and could probably be almost halved in length by counting Jan & Feb as
Months 13 & 14 of the previous year, as Zeller did.


If one can run XP batch, I suppose one can run WSH CSCRIPT javascript or
vbscript. Would those be appreciably slower? I have a wide variety of
javascript/jscript date algorithms on my site, including Y M D to Y W D
and back. Indeed, <URL:http://www.merlyn.demon.co.uk/batfiles.htm#WSH>
contains something like :-


To get ISO 8601 Week Number

See in datefmts for ISO 8601; weekinfo, weekcalc for the function.

C:\EPHEMERA>type calw.js
function YMD2YWD(y, m, d) { // ISO 8601 WkNo. m = 1..12 (ex i3.js)
var ms1d = 864e5, ms7d = 7*ms1d
var DC3 = Date.UTC(y, m-1, d+3)/ms1d, DoW = 1 + (DC3+7777777)%7
var AWN = Math.floor(DC3/7) // an Absolute Week Number
var Wyr = new Date(AWN*ms7d).getUTCFullYear()
return [Wyr, AWN - Math.floor(Date.UTC(Wyr, 0, 0)/ms7d), DoW ] }

var A = WScript.Arguments
YWD = YMD2YWD(+A(0), +A(1), +A(2))
WScript.echo( "@echo off" )
WScript.echo( " SET YYYYWWD=" + ((YWD[0]*100+YWD[1])*10+YWD[2]) )
WScript.echo( " SET YYYY=" + YWD[0] )
WScript.echo( " SET WW=" + ( (w=YWD[1]) > 9 ? w : "0"+w ) )
WScript.echo( " SET D=" + YWD[2] )

C:\EPHEMERA>cscript //nologo calw.js 2006 1 1
@echo off
SET YYYYWWD=2005527
SET YYYY=2005
SET WW=52
SET D=7

which can be redirected to $$$.BAT and executed to set the Environment
(though there must be better ways to get the result back).

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20 ; WinXP.

Timo Salmi

unread,
Nov 7, 2006, 11:29:07 AM11/7/06
to
Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:

> Timo Salmi <t...@uwasa.fi> writes:
> That contains the almost-new
> Subject: 149) How to calculate a date's week number with a pure cmd
> script?

> That looks like the ISO 8601 number, in which case it is necessary to
> get also the Year Number. 2006-01-01 = 2005-W52-7. But your code gives
> me 53, so I don't know what sort of Week Number you're calculating - or
> is it just a bug?

John, I have no idea. The algorithm is not mine. Mine is just the batch
interpretation. The algorithm is
http://www.tondering.dk/claus/cal/node8.html#SECTION00880000000000000000

I'll link the Message-Id of your posting.

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

Tika

unread,
Nov 7, 2006, 1:02:30 PM11/7/06
to
Dr J R Stockton wrote:
> If one can run XP batch, I suppose one can run WSH CSCRIPT javascript or
> vbscript. Would those be appreciably slower? I have a wide variety of

WSH is switched off on many machines.

Tika

unread,
Nov 7, 2006, 1:06:59 PM11/7/06
to
Timo Salmi wrote:
> Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
>> Timo Salmi <t...@uwasa.fi> writes:
>> That contains the almost-new
>> Subject: 149) How to calculate a date's week number with a pure cmd
>> script?
>
>> That looks like the ISO 8601 number, in which case it is necessary to
>> get also the Year Number. 2006-01-01 = 2005-W52-7. But your code gives
>> me 53, so I don't know what sort of Week Number you're calculating - or
>> is it just a bug?
>
> John, I have no idea. The algorithm is not mine. Mine is just the batch
> interpretation. The algorithm is
> http://www.tondering.dk/claus/cal/node8.html#SECTION00880000000000000000

Sorry, I replied too quickly and didn't spot that one.

2006-01-01 _is_ 2005-W53, not week 52. So, the script is correct.
Please refer to ISO 8601 for clarification.

Alexander Suhovey

unread,
Nov 7, 2006, 4:51:27 PM11/7/06
to
"Tika" <ti...@doesntexist.org> wrote in message
news:WS34h.4542$YA3....@newsfe7-win.ntli.net...

Huh?..

Can you please elaborate more how an why it is "switched off on many
machines"? I'd like to know where is that "swith". In several years I
didn't see a single Windows-based installation where WSH didn't work.
Actually I never seen that.

Or do you mean earlier versions of WIndows that do not have WSH built-in?

--
Alexander Suhovey

Tika

unread,
Nov 7, 2006, 5:09:35 PM11/7/06
to
Alexander Suhovey wrote:
> Can you please elaborate more how an why it is "switched off on many
> machines"? I'd like to know where is that "swith". In several years I
> didn't see a single Windows-based installation where WSH didn't work.
> Actually I never seen that.

Because there were lots of security issues with WSH in the past, many
companies still have it disabled by default.

Have a look at www.securityfocus.com and search for WSH.


> Or do you mean earlier versions of WIndows that do not have WSH built-in?

No.

Alexander Suhovey

unread,
Nov 7, 2006, 5:58:51 PM11/7/06
to
"Tika" <ti...@doesntexist.org> wrote in message
news:zu74h.4110$TH3....@newsfe2-gui.ntli.net...

>
> Have a look at www.securityfocus.com and search for WSH.
>
OK, I did that.

Came up with one advisory (2003) and three vulnerabilities (1999, 2000,
2003) and only one of them talks about WSH directly. Doesn's look like
something that would justify dumping THE scripting solution for the OS and
still keeping it off.

Do you have any other references to back up your statement (no offence
meant)?

--
Alexander Suhovey


Tika

unread,
Nov 7, 2006, 7:28:42 PM11/7/06
to

You mean companies that dumped the scripting host until now?

Todd Vargo

unread,
Nov 7, 2006, 7:52:06 PM11/7/06
to

"Alexander Suhovey" <asuh...@gmail.com> wrote in message
news:eir38l$2bib$1...@news.mtu.ru...

Subject line changed to reflect the discussion changed.

Please don't let misplaced remarks sidetrack your discussion.
Tika's opinion had/has no relevance to what was being discussed.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)


Alexander Suhovey

unread,
Nov 8, 2006, 4:53:47 AM11/8/06
to
"Tika" <ti...@doesntexist.org> wrote in message
news:_w94h.16225$r4.1...@newsfe3-gui.ntli.net...

> Alexander Suhovey wrote:
>>
>> Do you have any other references to back up your statement (no offence
>> meant)?
>
> You mean companies that dumped the scripting host until now?

That will do, but I was more interested in public documents that would
advise doing that. Like security best practices or security guides or
something. Something that these companies could have based their descision
on.


--
Alexander Suhovey

Alexander Suhovey

unread,
Nov 8, 2006, 4:54:36 AM11/8/06
to
"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:WS94h.1237$6t...@newssvr11.news.prodigy.com...

> Subject line changed to reflect the discussion changed.

Thank you for reminding and sorry for hijacking the thread.

--
Alexander SUhovey

foxidrive

unread,
Nov 8, 2006, 5:37:23 AM11/8/06
to
>> Alexander Suhovey wrote:
>>>
>>> Do you have any other references to back up your statement (no offence
>>> meant)?

I have my recollections of the past discussions about it.

Dr J R Stockton

unread,
Nov 8, 2006, 10:29:34 AM11/8/06
to
In message <4550b455$0$16502$9b53...@news.fv.fi>, Tue, 7 Nov 2006
18:29:07, Timo Salmi <t...@uwasa.fi> writes

>Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
>> Timo Salmi <t...@uwasa.fi> writes:
>> That contains the almost-new
>> Subject: 149) How to calculate a date's week number with a pure cmd
>> script?
>
>> That looks like the ISO 8601 number, in which case it is necessary to
>> get also the Year Number. 2006-01-01 = 2005-W52-7. But your code gives
>> me 53, so I don't know what sort of Week Number you're calculating - or
>> is it just a bug?
>
>John, I have no idea. The algorithm is not mine. Mine is just the batch
>interpretation. The algorithm is
>http://www.tondering.dk/claus/cal/node8.html#SECTION00880000000000000000
>
>I'll link the Message-Id of your posting.

I'm assuming that Tika is you, Timo (using UK time??).


The algorithm at that link, done by hand, gives Week 52 for that date
(and so does my code (Pascal & Javascript, independent & different), and
my Institute of Physics diaries for 2005 & for 2006).

Your code, copy'n'pasted, gives me

31.12.2005 Week number 52
1.1.2006 Week number 53
2.1.2006 Week number 1

which cannot be right for ISO 8601 where all weeks have 7 days.

Since WSH is available by default, it might provide a useful means of
testing pure-batch algorithms for which the right result is not obvious
by inspection but for which WSH code is available.
--
(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.

Tika

unread,
Nov 8, 2006, 2:36:58 PM11/8/06
to
Dr J R Stockton wrote:
> I'm assuming that Tika is you, Timo (using UK time??).

No.


> The algorithm at that link, done by hand, gives Week 52 for that date
> (and so does my code (Pascal & Javascript, independent & different), and
> my Institute of Physics diaries for 2005 & for 2006).

So these algorithms must be wrong.


> Your code, copy'n'pasted, gives me
>
> 31.12.2005 Week number 52
> 1.1.2006 Week number 53

Which is correct.
2006-01-01 was a Sunday. A new week starts on Monday.

From Wikipedia:

* If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in
week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week
52 or 53 of the previous year.


> 2.1.2006 Week number 1

Correct.

Tika

unread,
Nov 8, 2006, 2:43:24 PM11/8/06
to
Tika wrote:
>> The algorithm at that link, done by hand, gives Week 52 for that date
>> (and so does my code (Pascal & Javascript, independent & different), and
>> my Institute of Physics diaries for 2005 & for 2006).
>
> So these algorithms must be wrong.

Now I got confused again. ;)
Nope, sorry, week 52 is correct. I'd also used a wrong calendar.


>> 2.1.2006 Week number 1
>
> Correct.

That's the only thing I'm really sure about. ;-)

Dr J R Stockton

unread,
Nov 9, 2006, 7:18:09 AM11/9/06
to
In message <ulq4h.9043$hK2....@newsfe3-win.ntli.net>, Wed, 8 Nov 2006
19:36:58, Tika <ti...@doesntexist.org> writes

>Dr J R Stockton wrote:
>> I'm assuming that Tika is you, Timo (using UK time??).
>
>No.

Good. Apologies to Timo.

>> The algorithm at that link, done by hand, gives Week 52 for that date
>> (and so does my code (Pascal & Javascript, independent & different), and
>> my Institute of Physics diaries for 2005 & for 2006).
>
>So these algorithms must be wrong.

It seems unlikely that the IoP would get it wrong; they've been putting
ISO WN in diaries since 1992 or earlier. And my algorithms have been
well-tested and publicly visible for years.

>> Your code, copy'n'pasted, gives me
>> 31.12.2005 Week number 52
>> 1.1.2006 Week number 53
>
>Which is correct.
>2006-01-01 was a Sunday. A new week starts on Monday.
>
>From Wikipedia:
>
>* If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in
>week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week
>52 or 53 of the previous year.

True - though don't over-trust Wiki. January 1st can be in Week 53, but
that one was not.

>> 2.1.2006 Week number 1
>
>Correct.

I never doubted that. It was given, with 31.12.2005, to show that the
code gives three different week numbers on three consecutive days, which
cannot be correct as all ISO weeks are 7 days long.


--
(c) John Stockton, Surrey, UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.

Dr J R Stockton

unread,
Nov 9, 2006, 7:22:31 AM11/9/06
to
In message <wrq4h.9044$hK2....@newsfe3-win.ntli.net>, Wed, 8 Nov 2006
19:43:24, Tika <ti...@doesntexist.org> writes


Historic evidence shows that an ISO week number algorithm needs to be
tested exhaustively, using all 14 year types, for which a 28-year span
not spanning a missing XX00-02-29 suffices. Granted, there's no real
need to test all of the middles of more than one year.

One can be absolutely sure that Thursday January 4th will be Week 1 Day
4 - and that in fact occurs in 2007; and reliable code for incrementing
the Gregorian Date exists.

So, starting with 2007-01-04 Thu = 2007-W01-4 :
Repeat
Convert Y M D to Y' W D ;
Check that D increments cyclically 1..7 ;
When D rolled over, check that W increments cyclically 1..52/53 ;
When W rolled over, check that Y increments ;
On each YYYY-01-04, check that W=1 and Y'=Y ;
Increment the Gregorian date until at least 2035-01-04.

Those checks can of course be easily coded and tested.

Timo Salmi

unread,
Nov 10, 2006, 2:10:27 AM11/10/06
to
Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> I'm assuming that Tika is you, Timo (using UK time??).

Concerning that aspect. I do not post anonymously on the Usenet news. It
is not my habit. I always use my own identity. Thus there is no need for
anyone to guess when it's yours truly or not. If my name and address are
not there then you can be certain that it is someone else.

0 new messages