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

print monthly calendar from command line?

2,688 views
Skip to first unread message

beli...@aol.com

unread,
Jul 25, 2004, 6:45:57 PM7/25/04
to
Does anyone of a command line program for the Windows NT/2000/XP
console that will print a calendar of (say) July 2004 when the command
'cal 7 2004' is issued?

Paul R. Sadowski

unread,
Jul 25, 2004, 7:18:04 PM7/25/04
to
<beli...@aol.com> wrote in message
news:3064b51d.04072...@posting.google.com...

> Does anyone of a command line program for the Windows NT/2000/XP
> console that will print a calendar of (say) July 2004 when the command
> 'cal 7 2004' is issued?

Yes, but god knows where i got it. You can try emailing the author:
C:\Users\sadowski [(firecat) 19:11, Sun 07/25/2004] cal /?
Usage: cal [[month] year]
Ex: cal 3 2025 (Prints calendar for Mar 2025)
Ex: cal 2025 (Prints calendar for year 2025)
Ex: cal (Prints calendar for current year)
Month should be 1-12 and year should be greater than 1776.
POC: lvas...@tiac.net

C:\Users\sadowski [(firecat) 19:12, Sun 07/25/2004] cal 7 2004

July 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31


Paul R. Sadowski

unread,
Jul 25, 2004, 7:22:46 PM7/25/04
to
Here's a version.
http://www.geocities.com/urifrid/soft.html

Console bundle 1: Linux Ports


"Paul R. Sadowski" <vzn...@mailshell13.mailshell.com.NOWORMS> wrote in
message news:McXMc.9609$qT3....@nwrddc03.gnilink.net...

Andrew H. Carter (Applied ROT 17 Left, for Email do 17 Right)

unread,
Jul 25, 2004, 8:00:42 PM7/25/04
to


Try this:

http://unicorn.us.com/pub/cal40.zip

NAME
cal - displays a calendar
SYNOPSIS
cal [options] [[num_month] year]
cal [options] [word_month] [year]
DESCRIPTION
By default, cal will display a calendar for the current month with the current day marked. By
specifing certain arguments, cal will display a calendar for a whole year or a specified month
and year.

The transition from the Julian to Gregorian calendar is assumed to have occured in 1752 on the
3rd of September. Ten days following that date were eliminated by the reformation, so the
calendar for that month is a bit unusual.

If displaying a calendar in the single-month format, cal will look for a date file. If found,
cal will read the file, looking for special date descriptions for that month which will be
displayed to the right of the calendar. By default, up to 24 appointments may be displayed per
month. If the current date happens to fall on one of these special dates, it will be flagged by
an asterisk. If there is room, appointments for the next month may also be displayed with some
limitations (currently, special dates such as the 3rd Thursday of will not be calculated for
next month).

cal can also optionally use colors when displaying the calendar. It will not display colors any
time the calendar is not directly displaying on the console. This is generally the desired
behavior when your redirecting cal's output to another program or a file.

ARGUMENTS
A verbally-specified month may be entered without specifying a year in the argument list;
however, a single numerical argument will be interpreted as a year. Only the first 3 characters
of the month name are significant for a verbally-specified month. NOTE: The command "cal 10"
refers to 10 AD, not October, and not 1910.

The available options are:

--3[months]
Display previous/current/next month together. This option will be ignored when displaying a
full year.
--a[ppts]
Maximum number of appointments to display. Minimum is 8, maximum is 50, default is 24.
--col[or-file]=filename
Read color definitions from `filename' (default color filename depends on operating system).
--con[tinue]=n
Display the next n successive months starting with the month specified.
--d[ata-file]=filename
Read appointments from `filename' (default appointment data filename depends on operating
system). You may use -d up to 8 times in a commandline to specify multiple data file names.
--e[urope]
Use European format (first weekday is Monday).
--f[uture]
If current month is displayed, then show only future appointments from the date file, not
appointments that are past. This allows room for other descriptions with future dates to be
displayed. As time progresses through the month, old descriptions are discarded and newer ones
are used. The --future switch affects only the display for the current month, and not other
months.
--j[ulian]
Display Julian dates (days one-based, numbered from January 1.
--m[onday]
Display Monday as the first day of the week (same as --europe)
--noc[olor]
Inhibit the use of colors.
--nod[ata]
Do not try to read any appointment data file.
--p[ause]
Pause before exiting and prompt for a keystroke.
--th[ismonth]
Disable display of next month appointments; show only current month's.
--to[day]
Show only today's appointments.
--u[se-color]
Allow the use of colors.
--y[ear]
Display a calendar for the current year.


I just downed it and love it. It even supports redirection:

Typing this:

cal 2004 > Calendar.txt


Produced:


2004

January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6
4 5 6 7 8 9 10 8 9 10 11 12 13 14 7 8 9 10 11 12 13
11 12 13 14 15 16 17 15 16 17 18 19 20 21 14 15 16 17 18 19 20
18 19 20 21 22 23 24 22 23 24 25 26 27 28 21 22 23 24 25 26 27
25 26 27 28 29 30 31 29 28 29 30 31

April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 1 2 3 4 5
4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12
11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19
18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26
25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30
30 31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4
4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11
11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18
18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25
25 26 27 28 29 30 31 29 30 31 26 27 28 29 30

October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3 4
3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11
10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18
17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25
24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31
31


Typing this:

cal > Calmonth.txt


Produced:


July 2004 2: Rent is due!
Su Mo Tu We Th Fr Sa 2: --- Payday! ---
1 2 3 4: Independence Day
4 5 6 7 8 9 10 6: Take out the garbage
11 12 13 14 15 16 17 13: Take out the garbage
18 19 20 21 22 23 24 16: --- Payday! ---
<25>26 27 28 29 30 31 20: Take out the garbage
23: JACO meeting
*25: Daily reminder: Get some exercise!
27: Take out the garbage
30: --- Payday! ---


Did I mention that I love this proggie, and I just downed it:

Found the link here:

http://unicorn.us.com/cal.html


--
Sincerely, | (©) (©)
| ------ooo--(_)--ooo------
Andrew H. Carter | /// \\\
d(-_-)b |

Ted Davis

unread,
Jul 25, 2004, 10:05:47 PM7/25/04
to
On 25 Jul 2004 15:45:57 -0700, beli...@aol.com wrote:

Yes, cal.exe. Unfortunately, I don't have a clue where it got it.


T.E.D. (tda...@gearbox.maem.umr.edu - e-mail must contain "T.E.D." or my .sig in the body)

KC Wong

unread,
Jul 25, 2004, 11:51:59 PM7/25/04
to
> >Does anyone of a command line program for the Windows NT/2000/XP
> >console that will print a calendar of (say) July 2004 when the command
> >'cal 7 2004' is issued?
>
> Yes, cal.exe. Unfortunately, I don't have a clue where it got it.

Is there any information available when you right-click|Properties|Version
on cal.exe?


Timo Salmi

unread,
Jul 26, 2004, 1:31:46 AM7/26/04
to
Ted Davis <tda...@gearbox.maem.umr.edu> wrote:
> On 25 Jul 2004 15:45:57 -0700, beli...@aol.com wrote:
> >Does anyone of a command line program for the Windows NT/2000/XP
> >console that will print a calendar of (say) July 2004 when the command
> >'cal 7 2004' is issued?

> Yes, cal.exe. Unfortunately, I don't have a clue where it got it.

Also gawk can be used. But I at least know of

41332 Jan 23 1995 ftp://garbo.uwasa.fi/pc/calendar/cal33.zip
cal33.zip Display a calendar for a month or year, Unixish, A.Matulich

but that is for plain MS-DOS, so I can't know off-hand what will
happen under NT/XP.

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 batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip

Andrew H. Carter (Applied ROT 17 Left, for Email do 17 Right)

unread,
Jul 26, 2004, 2:13:58 AM7/26/04
to
On Sun, 25 Jul 2004 20:00:42 -0400, "Andrew H. Carter
(Applied ROT 17 Left, for Email do 17 Right)"
<lvjg...@knuubxdcq.wnc> wrote:

>cal 2004 > Calendar.txt

For best results view in fixed pitch font. I have a 98SE
machine and the proggie doesn't mention whether or not it
could work on XP, though from the date created in the
readme:

(c) 1993-2001 by Unicorn Research Corporation
http://unicorn.us.com.


Makes me think it may/maynot work, you can but try.

From the blurb at: http://unicorn.us.com/software.html

cal (unix, free)
Unix cal replacement command. Compatible with the standard
unix cal, but adds colors and powerful support for
appointments, both individual and periodic.


Though it does work on 98SE. I've run accross a couple
other proggies like that.

Ted Davis

unread,
Jul 26, 2004, 9:22:15 AM7/26/04
to

Huh? It is a Win32 console app that doesn't even have a readable
copyright string in the file. The only thng that might be of use is
this string that the syntax message contains:
"POC: lvas...@tiac.net"
A search on that turned up a home page that resolves to Earthlink and
throws 404 errors.


T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

Ted Davis

unread,
Jul 26, 2004, 9:24:19 AM7/26/04
to
On 26 Jul 2004 08:31:46 +0300, t...@UWasa.Fi (Timo Salmi) wrote:

>Ted Davis <tda...@gearbox.maem.umr.edu> wrote:
>> On 25 Jul 2004 15:45:57 -0700, beli...@aol.com wrote:
>> >Does anyone of a command line program for the Windows NT/2000/XP
>> >console that will print a calendar of (say) July 2004 when the command
>> >'cal 7 2004' is issued?
>
>> Yes, cal.exe. Unfortunately, I don't have a clue where it got it.
>
>Also gawk can be used. But I at least know of

True, but I got cal to use as a front end or subprogram for gawk
scripts.

Phred

unread,
Jul 26, 2004, 10:05:43 AM7/26/04
to
In article <csh8g0pg24qci9hfh...@4ax.com>,
"Andrew H. Carter (Applied ROT 17 Left, for Email do 17 Right)"
<lvjg...@knuubxdcq.wnc> wrote:
>On 25 Jul 2004 15:45:57 -0700, beli...@aol.com wrote:
>
>>Does anyone of a command line program for the Windows NT/2000/XP
>>console that will print a calendar of (say) July 2004 when the command
>>'cal 7 2004' is issued?
>Try this:
>
>http://unicorn.us.com/pub/cal40.zip

Thanks very much for this link Andrew. I asked a similar question in
aus.computers and alt.comp.freeware the other evening and got several
pointers; but cal40 looks as good as any, and I like the fact that the
author at least knows about Gregorian dates.
[Added the other two groups mentioned above to the distribution.]

For those who came in late:
Suggest you go to <http://unicorn.us.com/pub/> from where you can see
the direct link to cal40.zip and the cal40/ directory. In the latter
you will find cal.html which explains a lot, and readme.cal; also the
source files (src/) for those interested in the nitty-gritty.

Cheers, Phred.

--
ppnerk...@THISyahoo.com.INVALID

Andrew H. Carter (Applied ROT 17 Left, for Email do 17 Right)

unread,
Jul 26, 2004, 10:32:08 AM7/26/04
to


BTW, I did some testing on my 98SE machine:

1) The farthest the calendar will go without screwing up is
2045 AD , course by then I'd be 84 and not in too much need
of a comp., prolly dead by then.

2) I created a batch so that one could print a whole years
"appointment book":

@echo off
IF EXIST C:\Windows\Desktop\CalOut.txt DEL C:\Windows\Desktop\CalOut.txt
FOR %%a IN (JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC) DO Cal --th %%a | ECHO.>> C:\Windows\Desktop\CalOut.txt

Notepad C:\Windows\Desktop\CalOut.txt

NOTE: The parameter "--th" to supress future months appointments,
needs to be in front of the month parameter (and in direct
commandline usage as well) for it to work. I inserted an ECHO
to give it a visible break up, else it will run on in together.


Here is a sample output:

January 2004 1: New Year's Day


Su Mo Tu We Th Fr Sa 2: --- Payday! ---

1 2 3 4: Someone else will be 34 today
4 5 6 7 8 9 10 6: Trash day
11 12 13 14 15 16 17 9: Noah's 5th birthday
18 19 20 21 22 23 24 10: Rent is due!
25 26 27 28 29 30 31 11: Kim's 51st birthday
13: Debra's 48th birthday
13: Trash day
16: --- Payday! ---
19: Martin Luther King Day
20: Trash day
27: Trash day
30: --- Payday! ---

February 2004 10: Rent is due!
Su Mo Tu We Th Fr Sa 10: Trash day
1 2 3 4 5 6 7 11: John's 41st birthday
8 9 10 11 12 13 14 13: --- Payday! ---
15 16 17 18 19 20 21 14: St. Valentine's Day
22 23 24 25 26 27 28 17: Trash day
29 24: Trash day
26: Catherine's 44th birthday
27: --- Payday! ---

March 2004 6: Mom's 73rd birthday
Su Mo Tu We Th Fr Sa 9: Trash day
1 2 3 4 5 6 10: Rent is due!
7 8 9 10 11 12 13 12: --- Payday! ---
14 15 16 17 18 19 20 14: R's 54th birthday
21 22 23 24 25 26 27 16: Trash day
28 29 30 31 17: St. Patrick's Day
18: Hannah's 3rd birthday
23: Trash day
26: --- Payday! ---
30: Trash day

April 2004 1: All Fool's Day
Su Mo Tu We Th Fr Sa 5: Matthew's 11th birthday
1 2 3 6: Trash day
4 5 6 7 8 9 10 9: --- Payday! ---
11 12 13 14 15 16 17 10: Rent is due!
18 19 20 21 22 23 24 13: Trash day
25 26 27 28 29 30 15: Income Tax return due
20: Trash day
20: *** Take out the Recyclables ***
23: --- Payday! ---
27: Trash day


With some more tweaking, who knows what else. Changing the
colors is easy. When it says that using a background and
foreground color in the same group, (8-15, the foreground
will be changed to one of 0-7 and the text will flash, it
will only flash in full screen mode, not window. mode.

Did I mention that I love this program? :-)

Dr John Stockton

unread,
Jul 26, 2004, 7:18:32 AM7/26/04
to
JRS: In article <csh8g0pg24qci9hfh...@4ax.com>, dated
Sun, 25 Jul 2004 20:00:42, seen in news:alt.msdos.batch.nt, Andrew H.

Carter (Applied ROT 17 Left, for Email do 17 Right)
<lvjg...@knuubxdcq.wnc> posted :

>On 25 Jul 2004 15:45:57 -0700, beli...@aol.com wrote:
>
>>Does anyone of a command line program for the Windows NT/2000/XP
>>console that will print a calendar of (say) July 2004 when the command
>>'cal 7 2004' is issued?
>
>
>Try this:
>
>http://unicorn.us.com/pub/cal40.zip
>
>NAME
>cal - displays a calendar
>SYNOPSIS
>cal [options] [[num_month] year]
>cal [options] [word_month] [year]
>DESCRIPTION
>By default, cal will display a calendar for the current month with the current
>day marked. By
>specifing certain arguments, cal will display a calendar for a whole year or a
>specified month
>and year.
>
>The transition from the Julian to Gregorian calendar is assumed to have occured
>in 1752 on the
>3rd of September. Ten days following that date were eliminated by the
>reformation, so the
>calendar for that month is a bit unusual.


Not entirely reliable, then. Eleven days were omitted here; civil
1752-09-03..13 did not exist. See what the output actually says for
1752 - actually Wed Sep 02 was followed by Thu Sep 14.

Does it tackle the question of Alaska's more complex hiatus?

It is unwise in using the term "Julian date", which has multiple
meanings. ISO 8601 calls it 'Ordinal Day of Year' / 'Ordinal Date'.

It is unwise in "--e[urope] Use European format (first weekday is
Monday)." - that is an International Standard, not specifically
European.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
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.

Andrew H. Carter (Applied ROT 17 Left, for Email do 17 Right)

unread,
Jul 26, 2004, 3:02:21 PM7/26/04
to


It could use some reworking, I did a test to the year 3000
(I think) and the max it showed was 2196, or some such, but
when I did further testing of computer date and the program
date, the maximun usable year is 2047 AD, usable as in both
were in sync. I guess software writers figure, well it's
either a fad or the code will be obsolete by that times, so
why bother?

Dr John Stockton

unread,
Jul 27, 2004, 7:18:42 AM7/27/04
to
JRS: In article <60lag0p4a0gvt0ocb...@4ax.com>, dated
Mon, 26 Jul 2004 15:02:21, seen in news:alt.msdos.batch.nt, Andrew H.

Carter (Applied ROT 17 Left, for Email do 17 Right)
<lvjg...@knuubxdcq.wnc> posted :
>On Mon, 26 Jul 2004 12:18:32 +0100, Dr John Stockton
><sp...@merlyn.demon.co.uk> wrote:
>
>>JRS: In article <csh8g0pg24qci9hfh...@4ax.com>, dated
>>Sun, 25 Jul 2004 20:00:42, seen in news:alt.msdos.batch.nt, Andrew H.
>>Carter (Applied ROT 17 Left, for Email do 17 Right)
>><lvjg...@knuubxdcq.wnc> posted :
>>>On 25 Jul 2004 15:45:57 -0700, beli...@aol.com wrote:
>>>
>>>>Does anyone of a command line program for the Windows NT/2000/XP
>>>>console that will print a calendar of (say) July 2004 when the command
>>>>'cal 7 2004' is issued?
>>>
>>>
>>>Try this:
>>>
>>>http://unicorn.us.com/pub/cal40.zip
>>>
>>>NAME
>>>cal - displays a calendar
>>>SYNOPSIS
>> ...

>>Not entirely reliable, then. Eleven days were omitted here; civil
>>1752-09-03..13 did not exist. See what the output actually says for
>>1752 - actually Wed Sep 02 was followed by Thu Sep 14.
>>
>>Does it tackle the question of Alaska's more complex hiatus?
>>
>>It is unwise in using the term "Julian date", which has multiple
>>meanings. ISO 8601 calls it 'Ordinal Day of Year' / 'Ordinal Date'.
>>
>>It is unwise in "--e[urope] Use European format (first weekday is
>>Monday)." - that is an International Standard, not specifically
>>European.
>>
>
>
>It could use some reworking, I did a test to the year 3000
>(I think) and the max it showed was 2196, or some such, but
>when I did further testing of computer date and the program
>date, the maximun usable year is 2047 AD, usable as in both
>were in sync. I guess software writers figure, well it's
>either a fad or the code will be obsolete by that times, so
>why bother?


For current dates, one does not really need a computer calendar; there
are diaries, wall-calendars, etc. Except as a programming exercise, a
computer calendar is really useful only for non-current dates. The
programmer can have no idea of the purposes that a distributed program
may be used for.

Such a program should be limited to the range of dates that the
programmer tests over; for example, a date program for UK & NA should be
aware of the importance of 1752. Either the range should be limited to
1753 and up, or the program should be identified as Gregorian, or the
transition should be properly handled. Note that NA is more than just
CONUS.

A calendar algorithm that can properly handle Feb 2000 (i.e. by applying
the 4, 100, & 400 year rules) can handle all Gregorian years, within
limits imposed by size and perhaps positivity of the year number. A
failure in AD 2048 is a BAD SIGN, and makes one wonder whether the
programmer's talent was adequate.

Since this is the NT group, WSH must be available; the subject task
should fairly easily be possible with a VBscript or Jscript program,
AFAICS.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
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.

Timo Salmi

unread,
Jul 27, 2004, 1:54:37 PM7/27/04
to
Dr John Stockton <sp...@merlyn.demon.co.uk> wrote:
> Since this is the NT group, WSH must be available; the subject task
> should fairly easily be possible with a VBscript or Jscript program,

Taken from the infamous FAQ. For today. Should be easy to convert
for a general date.

@echo off & setlocal enableextensions
::
:: Make a temporary folder
if not exist c:\mytemp mkdir c:\mytemp
::
:: Build a Visual Basic Script
findstr "'%skip%VBS" "%~f0" > c:\mytemp\tmp$$$.vbs
:: Run it with Microsoft Windows Script Host Version 5.6
cscript //nologo c:\mytemp\tmp$$$.vbs
::
:: Call the command line script the script host built
call c:\mytemp\tmp$$$.cmd
::
:: Clean up
for %%f in (c:\mytemp\tmp$$$.vbs c:\mytemp\tmp$$$.cmd) do (
if exist %%f del %%f)
rmdir c:\mytemp
::
:: Show the results
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_%
endlocal & goto :EOF
'
'The Visual Basic Script
Const ForReading = 1, ForWriting = 2, ForAppending = 8 'VBS
Dim DateNow, TimeNow, fso, f 'VBS
DateNow = Date 'VBS
TimeNow = Time 'VBS
Set fso = CreateObject("Scripting.FileSystemObject") 'VBS
Set f = fso.OpenTextFile("c:\mytemp\tmp$$$.cmd", ForWriting, True) 'VBS
f.WriteLine "@set dd_=" & Right(0 & DatePart("d", DateNow), 2) 'VBS
f.WriteLine "@set mm_=" & Right(0 & DatePart("m", DateNow), 2) 'VBS
f.WriteLine "@set yyyy_=" & DatePart("yyyy", DateNow) 'VBS
f.WriteLine "@set hh_=" & Right(0 & DatePart("h", TimeNow), 2) 'VBS
f.WriteLine "@set mi_=" & Right(0 & DatePart("n", TimeNow), 2) 'VBS
f.WriteLine "@set ss_=" & Right(0 & DatePart("s", TimeNow), 2) 'VBS
f.Close 'VBS
And example of the output
D:\TEST>cmdfaq
Date by %date% 16.03.2004
Time by %time% 8:27:15.47
dd_=16
mm_=03
yyyy_=2004
hh_=08
mi_=27
ss_=15

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

Dr John Stockton

unread,
Jul 28, 2004, 8:42:17 AM7/28/04
to
JRS: In article <ce64st$9...@poiju.uwasa.fi>, dated Tue, 27 Jul 2004
20:54:37, seen in news:alt.msdos.batch.nt, Timo Salmi <t...@UWasa.Fi>
posted :

>Dr John Stockton <sp...@merlyn.demon.co.uk> wrote:
>> Since this is the NT group, WSH must be available; the subject task
>> should fairly easily be possible with a VBscript or Jscript program,
>
>Taken from the infamous FAQ. For today. Should be easy to convert
>for a general date.

It's not a calendar, though.


> DateNow = Date 'VBS
> TimeNow = Time 'VBS

Almost infallible. But, if midnight occurs in between, in error.

I believe that a single variable Moment = Now can be used instead of
both of those.

> f.WriteLine "@set dd_=" & Right(0 & DatePart("d", DateNow), 2) 'VBS

Might be quicker if the 0 is already a string.
Right(100 + ... ought to beat Right(0 & ... where, as here, ... is
a number.
I think DatePart may be over-popular; Year() Month() Day() Hour()
Minute() Second() can be used instead.
I predict no perceptible difference, though.

>And example of the output

> dd_=16
> mm_=03
> yyyy_=2004

That's European-biased - a true internationalist would have the lines
that create YYYY MM DD in the opposite order ! <g>

I tried for a calendar myself in VBS & JS; but the code that I used in
the past to read command-line parameters does not now work, & I cannot
imagine why, unless a re-boot is needed.

--

Todd Vargo

unread,
Jul 28, 2004, 6:08:52 PM7/28/04
to

Dr John Stockton wrote:

> I tried for a calendar myself in VBS & JS; but the code that I used in
> the past to read command-line parameters does not now work, & I cannot
> imagine why, unless a re-boot is needed.

I'm interested, post the code for an examination.

--
Todd Vargo (remove hyphen to reply by email)


Dr John Stockton

unread,
Jul 29, 2004, 7:42:08 AM7/29/04
to
JRS: In article <2mqn1hF...@uni-berlin.de>, dated Wed, 28 Jul 2004
18:08:52, seen in news:alt.msdos.batch.nt, Todd Vargo
<todd_...@nccw.net> posted :

>
>Dr John Stockton wrote:
>
>> I tried for a calendar myself in VBS & JS; but the code that I used in
>> the past to read command-line parameters does not now work, & I cannot
>> imagine why, unless a re-boot is needed.
>
>I'm interested, post the code for an examination.

Your p l e a s and e keys appear intermittent.

I have not re-booted, but the VBS now works as below; the JS does not

C:\EPHEMERA>type cal.vbs

Set x = WScript.Arguments
WScript.echo "Result:", x.count, X(1)

C:\EPHEMERA>cscript //nologo cal.vbs 66 77 88
Result: 3 77

C:\EPHEMERA>type cal.js

x = WScript.Arguments
WScript.echo("Result:", x.length, typeof x, x[1], "OK")

C:\EPHEMERA>cscript //nologo cal.js 66 77 88
Result: 3 object OK


There used to be a 77 between the pair of spaces given by cal.js.

The code, given year and month in variables, for displaying a month's
calendar in a manner resembling

2004 January


Su Mo Tu We Th Fr Sa

1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

is basically trivial ; it is for example buried in js-clndr.htm via
below. The code for the year's calendar requires a little more work.
Neither are worth bothering with if reading parameters is unreliable.
In VBS, however, it might be better with simple things I don't yet know
about, such as the declaration of constant string arrays.

But the following new code seems to work, though not an exact match :


Set X = WScript.Arguments : '' WScript.echo "Parameters:", X(0), X(1)
Mo = X(0) : Yr = X(1)

YS = "JanFebMarAprMayJunJulAugSepOctNovDec"
MN = Mid(YS, 3*Mo-2, 3) : if MN="" then MN = Mo '' Month Name
WScript.echo " ", Yr, " ", MN
WScript.echo " Mo Tu We Th Fr Sa Su"
WD = WeekDay(DateSerial(Yr, Mo, 1), 2) '' Day Number of 1st
LD = Day(DateSerial(Yr, Mo+1, 0)) '' Last Day of month
Wk = Left(" ", (WD-1)*3) '' Previous month

for D = 1 to LD
Wk = Wk & " " & Right(100+D, 2) : WD = WD + 1
if (WD=8) or (D=LD) then WScript.echo Wk : WD = WD-7 : Wk = ""
next

Wscript.echo " ------ "


There will no doubt be a way of getting the month name from the number,
without supplying strings; and the day-names can be localised easily
enough. Months outside 1..12 are OK; the acceptance range is up to Nov
9999 and back to Jan -1900, but the lower limit of correctness is
questionable. The code may not be optimum.

To do the year as Jan Feb Mar / Apr ..., my first thought is to modify
the above to append onto an array element instead of echo, then print
the array quarterly; the final week, at least, will generally need
padding.

XP to a.m.b added, as it works in Win98.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Todd Vargo

unread,
Jul 29, 2004, 7:58:26 PM7/29/04
to

"Dr John Stockton" <sp...@merlyn.demon.co.uk> wrote in message
news:A3MMRpDQ...@merlyn.demon.co.uk...

> JRS: In article <2mqn1hF...@uni-berlin.de>, dated Wed, 28 Jul 2004
> 18:08:52, seen in news:alt.msdos.batch.nt, Todd Vargo
> <todd_...@nccw.net> posted :
> >
> >Dr John Stockton wrote:
> >
> >> I tried for a calendar myself in VBS & JS; but the code that I used in
> >> the past to read command-line parameters does not now work, & I cannot
> >> imagine why, unless a re-boot is needed.
> >
> >I'm interested, post the code for an examination.
>
> Your p l e a s and e keys appear intermittent.

Oh please, I offered to examine your code for discussion, not request just
to acquire it.

>
> I have not re-booted, but the VBS now works as below; the JS does not
>
> C:\EPHEMERA>type cal.vbs
>
> Set x = WScript.Arguments
> WScript.echo "Result:", x.count, X(1)
>
> C:\EPHEMERA>cscript //nologo cal.vbs 66 77 88
> Result: 3 77
>
> C:\EPHEMERA>type cal.js
>
> x = WScript.Arguments
> WScript.echo("Result:", x.length, typeof x, x[1], "OK")
>
> C:\EPHEMERA>cscript //nologo cal.js 66 77 88
> Result: 3 object OK
>
>
> There used to be a 77 between the pair of spaces given by cal.js.

That is because you have square [brackets] instead of (parenthesis).


> Neither are worth bothering with if reading parameters is unreliable.

They seem to work reliable for me. Try using parenthesis in your testing.

...


> There will no doubt be a way of getting the month name from the number,
> without supplying strings; and the day-names can be localised easily
> enough. Months outside 1..12 are OK; the acceptance range is up to Nov
> 9999 and back to Jan -1900, but the lower limit of correctness is
> questionable. The code may not be optimum.

Ok, this code may not be optimum either, but this is how I would rewrite it
for this side of the pond.

Set X = WScript.Arguments


Mo = X(0) : Yr = X(1)

WScript.Echo " " , Left(MonthName(Mo) & " ",13), _
Year(DateSerial(Yr, 1, 1))
For n=1 to 7:WN = WN & " " & Left(WeekdayName(n),2):Next
WScript.Echo WN

WD = WeekDay(DateSerial(Yr, Mo, 1)) '' Day Number of 1st


LD = Day(DateSerial(Yr, Mo+1, 0)) '' Last Day of month

Wk = Space((WD-1)*3) '' Previous month

For D = 1 To LD
Wk = Wk & " " & Right(" " & D, 2)
If (WD=7) Or (D=LD) Then
WScript.Echo Wk : WD = 1 : Wk = ""
Else


WD = WD + 1

End If
Next

Wscript.Echo " ------ "


E:\>cscript /nologo US-cal.vbs 7 2004
July 2004


Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

------

Ok, that's enough discussion from me on this. Like you mentioned, expanding
it to display a year is trivial.

Dr John Stockton

unread,
Jul 30, 2004, 1:00:40 PM7/30/04
to
JRS: In article <2mtiipF...@uni-berlin.de>, dated Thu, 29 Jul 2004
19:58:26, seen in news:alt.msdos.batch.nt, Todd Vargo
<todd_...@nccw.net> posted :
>

>"Dr John Stockton" <sp...@merlyn.demon.co.uk> wrote in message
>news:A3MMRpDQ...@merlyn.demon.co.uk...

>> C:\EPHEMERA>type cal.js


>>
>> x = WScript.Arguments
>> WScript.echo("Result:", x.length, typeof x, x[1], "OK")
>>
>> C:\EPHEMERA>cscript //nologo cal.js 66 77 88
>> Result: 3 object OK
>>
>>
>> There used to be a 77 between the pair of spaces given by cal.js.
>
>That is because you have square [brackets] instead of (parenthesis).

That seems unreasonable. But correct, and usable. Needs to be
investigated until understood.


> Year(DateSerial(Yr, 1, 1))
not just Year? Y2k fix?

I need next to try a javascript version; it's a more useful language,
with which I am more familiar. Basically done.

Versions of my VBS are now in my vb-dates.htm.

Timo Salmi

unread,
Jul 31, 2004, 3:19:10 PM7/31/04
to
Not a solution, but somewhat related. (Some wrapping might be sligthly
off.)

DRAFT: 71) Calendar elements: What weekday is December 31, 2004?

Utilizing a Visual Basic Script (VBScript):


@echo off & setlocal enableextensions

if not exist c:\mytemp mkdir c:\mytemp

echo>c:\mytemp\tmp$$$.vbs WScript.Echo
WeekDayName(Weekday(DateValue("December 31, 2004")),true)
for /f %%d in ('cscript //nologo c:\mytemp\tmp$$$.vbs') do set
wd_=%%d
for %%f in (c:\mytemp\tmp$$$.vbs) do if exist %%f del %%f
rmdir c:\mytemp
echo Weekday on December 31, 2004 is wd_=%wd_%
endlocal & goto :EOF
The output will be
D:\TEST>cmdfaq
Weekday on December 31, 2004 is wd_=Fri

Likewise:


@echo off & setlocal enableextensions

if not exist c:\mytemp mkdir c:\mytemp

echo>c:\mytemp\tmp$$$.vbs WScript.Echo
DatePart("y",DateValue("December 31, 2004"))
for /f %%d in ('cscript //nologo c:\mytemp\tmp$$$.vbs') do set
dn_=%%d
for %%f in (c:\mytemp\tmp$$$.vbs) do if exist %%f del %%f
rmdir c:\mytemp
echo The ordinal number day of year on December 31, 2004 is
dn_=%dn_%
endlocal & goto :EOF
The output will be
D:\TEST>cmdfaq
The ordinal number day of year on December 31, 2004 is dn_=366

Further information:


@echo off & setlocal enableextensions

if not exist c:\mytemp mkdir c:\mytemp

echo>c:\mytemp\tmp$$$.vbs WScript.Echo
DatePart("ww",DateValue("December 31, 2004"),vbMonday,vbFirstFourDays)
for /f %%w in ('cscript //nologo c:\mytemp\tmp$$$.vbs') do set
wn_=%%w
for %%f in (c:\mytemp\tmp$$$.vbs) do if exist %%f del %%f
rmdir c:\mytemp
echo The week number on December 31, 2004 is wn_=%wn_%
endlocal & goto :EOF
The output will be
D:\TEST>cmdfaq
The week number on December 31, 2004 is wn_=53

Finally, how many days are there in a month?


@echo off & setlocal enableextensions

:: Build a Visual Basic Script

if not exist c:\mytemp mkdir c:\mytemp

findstr "'%skip%VBS" "%~f0" > c:\mytemp\tmp$$$.vbs
::

:: Assume a local date format dd.mm.yyyy
:: Customize, if necessary
set month_=2
set year_=2004
::
:: Run the VBS script with Microsoft Windows Script Host Version 5.6


cscript //nologo c:\mytemp\tmp$$$.vbs

call c:\mytemp\tmp$$$.cmd
echo %mmdays_% days in %month_%.%year_%
::
:: Clean up
for %%f in (c:\mytemp\tmp$$$.vbs c:\mytemp\tmp$$$.cmd) do del %%f
rmdir c:\mytemp
endlocal & goto :EOF
'
'................................................................


'The Visual Basic Script
'
Const ForReading = 1, ForWriting = 2, ForAppending = 8 'VBS

Dim MyDate, mm, yyyy, DaysInMonth, fout, FSO 'VBS
'
Set WshShell = WScript.CreateObject("WScript.shell") 'VBS
mm=WshShell.ExpandEnvironmentStrings("%month_%") 'VBS
yyyy=WshShell.ExpandEnvironmentStrings("%year_%") 'VBS
'
For i = 28 to 32 'VBS
Mydate = CStr(i) & "." & CStr(mm) & "." & CStr(yyyy) 'VBS
If (IsDate(MyDate)) Then 'VBS
DaysInMonth = i 'VBS
End If 'VBS
Next 'VBS
'
Set FSO = CreateObject("Scripting.FileSystemObject") 'VBS
Set fout = FSO.OpenTextFile("c:\mytemp\tmp$$$.cmd", ForWriting,
true) 'VBS
fout.WriteLine "@set mmdays_=" & DaysInMonth 'VBS
fout.Close 'VBS
The output will be
D:\TEST>cmdfaq
29 days in 2.2004

Dr John Stockton

unread,
Aug 1, 2004, 9:24:11 AM8/1/04
to
JRS: In article <2b11265.04073...@posting.google.com>, dated
Sat, 31 Jul 2004 12:19:10, seen in news:alt.msdos.batch.nt, Timo Salmi
<t...@uwasa.fi> posted :

>Finally, how many days are there in a month?

> For i = 28 to 32 'VBS


> Mydate = CStr(i) & "." & CStr(mm) & "." & CStr(yyyy) 'VBS
> If (IsDate(MyDate)) Then 'VBS
> DaysInMonth = i 'VBS
> End If 'VBS
> Next 'VBS

32? I know you've had a 30-day Feb up there, but ...

Better to start at 31, and exit once a valid day is found.

I cannot test in on-topic systems; but

Y = 2004 : M = 2
document.write Day(DateSerial(Y, M+1, 0))

executed in <URL:http://www.merlyn.demon.co.uk/js-quick.htm> with the
VBS button demonstrates an even better algorithm, which should be OK for
you.

IMHO, in VBS as seen in News, DatePart is over-used and DateSerial is
under-used.

For applicable date algorithms, see both
<URL:http://www.merlyn.demon.co.uk/js-dates.htm> and
<URL:http://www.merlyn.demon.co.uk/vb-dates.htm> and general pages
linked from them.

News.c.l.j has developed some amazingly quicker methods than using dates
proper (conversion of YMD to a day or ms count cannot but be slow).

For example, to get the length of a month, just look it up in an array
[31, 0, 31, 30, ..., 31]. If the answer is zero, then it must be
February and one can then test the year number - for which there are
quicker ways than the obvious three straight divisibility rules. That
is, after all, how one would do it mentally.

--

Todd Vargo

unread,
Aug 1, 2004, 12:12:57 PM8/1/04
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:2b11265.04073...@posting.google.com...

> Not a solution, but somewhat related. (Some wrapping might be sligthly
> off.)
>
> DRAFT: 71) Calendar elements: What weekday is December 31, 2004?
>
> Utilizing a Visual Basic Script (VBScript):

If nothing else, your/our VBScript is coming along nicely. :)

Timo Salmi

unread,
Aug 1, 2004, 12:13:23 PM8/1/04
to
Dr John Stockton <sp...@merlyn.demon.co.uk> wrote:
> Timo Salmi <t...@uwasa.fi> posted :
> >Finally, how many days are there in a month?
> > For i = 28 to 32 'VBS
> > Mydate = CStr(i) & "." & CStr(mm) & "." & CStr(yyyy) 'VBS
> > If (IsDate(MyDate)) Then 'VBS
> > DaysInMonth = i 'VBS
> > End If 'VBS
> > Next 'VBS

> 32? I know you've had a 30-day Feb up there, but ...

Any month. February was just an example.

> Better to start at 31, and exit once a valid day is found.

For production runs, yes. However, for testing it was better the
other way round since I wanted to make sure that 32 will always be
invalid. Before the testing of IsDate(MyDate) I could not be
absolutely certain whether the VBS fuction really was about a valid
date _or_ a valid date format! It (fortunately) was about the
former.

A small beauty-flaw, no doubt, but inconsequential for speed.

0 new messages