[comp.binaries.ibm.pc.d] Good date programs

jbjones@marlin.NOSC.MIL (John B. Jones) (05/16/89)

I need a nice date program which I can use at the command line, which
won't expect a return or prompt me for a change, and which displays the
date and the day of the week.  The output will probably look like this:

	May 16, 1989 	Tuesday

If anyone has something like this  I'd be sooo happy to get it.

jbjones@marlin.nosc.mil

maa@nbires.nbi.com (Mark Armbrust) (05/17/89)

In article <1163@marlin.NOSC.MIL> jbjones@marlin.nosc.mil.UUCP (John B. Jones) writes:
>I need a nice date program which I can use at the command line, which
>won't expect a return or prompt me for a change, and which displays the
>date and the day of the week.  The output will probably look like this:
>
>	May 16, 1989 	Tuesday

If you are using CED you can make a clever alias (or put it in a batch file if
you are not):

syn date echo.|date %1|find /v "Enter"
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  (put this in batch file)

"echo." with no spaces, outputs a return that feeds to the date command's 
request for a new date, "find /v" keeps this request from showing up on the
console.

Typing "date" results in "Current date is Tue  5-16-1989".  The date can be
set by typing "date <newdate>".

This same alias can be used withthe "time" command.

Note that the "echo." command behaves a bit differently on various versions
of DOS (I'm running 3.30).  You may have to look around a bit to do this on
your version.  Generally, any command that does nothing and generates output
starting with a blank line can be used in place of the echo.  ("vol" is a
good choice, but it does cause a little extra disk access.)

Also note that since this uses pipes, you must be able to write into the 
current directory (won't work if you are on a read-only floppy).

Mark Armbrust
maa@nbires.nbi.com
maa@nbires.UUCP

ked@garnet.berkeley.edu (Earl H. Kinmonth) (05/17/89)

In article <392@nbires.nbi.com> maa@nbires.UUCP (Mark Armbrust) writes:
>In article <1163@marlin.NOSC.MIL> jbjones@marlin.nosc.mil.UUCP (John B. Jones) writes:
>>I need a nice date program which I can use at the command line, which
>>won't expect a return or prompt me for a change, and which displays the
>>date and the day of the week.  The output will probably look like this:
>
>If you are using CED you can make a clever alias (or put it in a batch file if
>you are not):

Any even better idea is to buy the Mortice Kern System Toolkit.  This gives
you a **IX like date with output that you can format to your heart's content.
The MKS Toolkit also gives you lots of other goodies like the korn shell,
a more that is useful, a complete version of vi, etc., etc.  I can't think
of any piece of MSDOS software that his a higher utility/price ratio than
MKS.

Disclaimer: Not only do I have no relation to MKS, the copy I have was
purchased out of pocket.  Once I saw what it could do, I coudn't wait
for the requisition to go through the University bureaucracy.

Earl H. Kinmonth
History Department
University of California, Davis
Davis, California  95616
916-752-1636 (2300-0800 PDT for FAX)
916-752-0776 (secretary)
ucbvax!ucdavis!ucdked!cck (email)
cc-dnet.ucdavis.edu [128.120.2.251]
	(request ucdked, login as guest)

mju@mudos.ann-arbor.mi.us (Marc Unangst) (05/18/89)

In article <24501@agate.BERKELEY.EDU>, ked@garnet.berkeley.edu (Earl H. Kinmonth) writes:
 >The MKS Toolkit also gives you lots of other goodies like the korn shell,
 >a more that is useful, a complete version of vi, etc., etc.  I can't think
 >of any piece of MSDOS software that his a higher utility/price ratio than
 >MKS.

Maybe the set of PiCnix utilities?  Their cost is zero, and (although they
don't include the "heavyweight" program like vi or ksh), they do include
versions of grep, ls, rm, touch, mv, etc.  They also include "ndate" (can't
be called "date" because of name conflicts with DOS), which is just like
the Unix version of "date".

You could also write a short C program to do this.  (Disclaimer: This
should work with Turbo C.  Although the Turbo C Bible says that all
the functions used are compatable with MSC, QuickC, Unix SysV C, and ANSI
C, your milage may vary.)

#include <time.h>
#include <stdio.h>

void main(void);
void main()
{
        printf("%s\n",ctime(time((time_t *) NULL)));
}

This simply prints the date and time in the form

        Wed May 17 15:39:36 1989

--  
Marc Unangst
UUCP smart    : mju@mudos.ann-arbor.mi.us
UUCP dumb     : ...!uunet!sharkey!mudos!mju
UUCP dumb alt.: ...!{ames,rutgers}!mailrus!clip!mudos!mju
Internet      : mju@mudos.ann-arbor.mi.us

foote@atlantis.Berkeley.EDU (Bill "Mr. Fun" Foote) (05/18/89)

It's pretty easy to write a date program in C.  I have one for the
IBM PC (and unix) that produces output like this:

	Today is Wednesday, May 17, 1989.
	Pacific Daylight Time is 2:59 PM.

I think that the program is about forty lines of source (and most of
that is things like arrays holding the names of months).  If anyone
wants, I can e-mail them the source and executable for this.


Bill Foote
foote@ernie.Berkeley.EDU
..!ucbvax!ernie!foote

lfk@mbio.med.upenn.edu (Lee Kolakowski) (05/18/89)

If you need to use command.com as opposed to MKS toolkits korn shell,
then you can use a rational echo and date by firing up debug and
changing the strings DATE and ECHO in command.com to date and echo.
DOS will then execute programs named date and echo rather than the
builtins.



--

Frank Kolakowski 

=====================================================================
|lfk@mbio.med.upenn.edu                 ||      Lee F. Kolakowski   |
|kolakowski@mscf.med.upenn.             ||	Univ. of Penna.     |
|c/o jes@eniac.seas.upenn.edu		||	Dept of Chemistry   |
|kolakowski@c.chem.upenn.edu		||	231 South 34th St.  |
|bcooperman.kolakowski@bionet-20.arpa	||	Phila, PA 19104     |
|AT&T:	1-215-898-2927			||--------------------------|
|#include <litigate.h>			||      One-Liner Here!     |
=====================================================================

ked@garnet.berkeley.edu (Earl H. Kinmonth) (05/18/89)

>Maybe the set of PiCnix utilities?  Their cost is zero, and (although they
>don't include the "heavyweight" program like vi or ksh), they do include

PiCnix doesn't include any middle weight utilities like sort either. In
the limited sense that almost anything **IX is more usable than
anything **DOS, PiCnix is worth looking at. IMHO it does not give you
anything that a a modestly experienced C programmer could not write for
[him|her]self or assemble from various pd items floating about.

Writing a usable vi and korn shell that actually work despite the
fundmentally brain-dead MSDOS platform is a programming tour-de-force!
MKS Toolkit is worth every penny.

13001_6035@uwovax.uwo.ca (05/18/89)

In article <1163@marlin.NOSC.MIL>, jbjones@marlin.NOSC.MIL (John B. Jones) writes:
> I need a nice date program which I can use at the command line, which
> won't expect a return or prompt me for a change, and which displays the
> date and the day of the week.  The output will probably look like this:
> 
> 	May 16, 1989 	Tuesday
What follows is what I think is a more efficient way of displaying
the time and the date under DOS 3.3.  Somehow I think this is a more
elegant approach than piping DATE and TIME into FIND.

-----SHOWDT.BAT BEGINS-----CUT HERE-----
@echo off
set oldprompt=%prompt%
prompt Date: $d$_Time: $t.
echo on

@echo off
echo.
prompt %oldprompt%
set oldprompt=
-----SHOWDT.BAT ENDS-----CUT HERE-----
-----NOTE THAT THE 5TH LINE IS INTENTIONALLY LEFT BLANK.

For those new to DOS 3.3, I will explain how this works.
1. @echo off
            Standard ECHO OFF command, but when in a batch file a
            command is preceded by an '@' then it is not echoed.
            This avoids the ugly C:\>ECHO OFF at the beginning of the
            batch-file.
2. set oldprompt=%prompt%
            Save the old environment PROMPT variable, so we get the same
            DOS prompt when we are done.
3. prompt Date: $d$_Time: $t.
            This sets the DOS prompt (normally something like "C:\>")
            to show up "Date: <date>" followed by a return ($_), followed
            by "Time: <time>."
4. echo on
            Activate achoing so we can see the prompt.
5. ---<INTENTIONALLY A BLANK LINE>---
            Do nothing.  This is to allow us to see the prompt.
6. @echo off
            Turn off echo for the rest.
7. echo.
            Put an extra blank line in.  This makes the output neater.
8. prompt %oldprompt%
            Restore the original prompt.
9. set oldprompt=
            Release environment space taken up by the temporary OLDPROMPT
            variable.

This will only work under DOS 3.3 or higher as the '@' prefix is not allowed
under lower versions.  If you want to call this from other batchfiles, then
you can use the
        CALL SHOWTD.BAT
command from within a batchfile.

If you don't have DOS 3.3, you can use the piping approach someone else
thought up, but it does do a lot of wasteful disk access or buy DOS 3.3!

ts@chyde.uwasa.fi (Timo Salmi LASK) (05/19/89)

Someone was looking for a utility just giving the date (with
weekday) and time without prompting for anything.  There is such a
utility within /pc/ts/tsutil25.arc.  It can be anonymous ftp:d from
128.214.12.3 at the University of Vaasa, Finland. 

...................................................................
Prof. Timo Salmi
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: vakk::salmi Bitnet: salmi@finfun

marks@tekigm2.MEN.TEK.COM (Mark D. Salzman) (05/22/89)

Here is another variation on the use of the prompt to show the time and
other good information. It creates a status line at the top of the screen
that is updated whenever the prompt is shown. It is somewhat slow on XT
class machines and my version is set up for color screens, so it would
need modification for monochrome. It's only drawback is that it clobbers
the top line, so programs that end up showing something there will be
affected. I set this up as a seperate batch file so I can type "prompt<cr>"
to disable it and run such programs, then call the batch file to restore it.

BTW, ANSI.SYS or an equivalent must be installed and the screen must be in
80 columb text mode for this to work right. It has been tested on DOS version
3.0 and up. This was inspired by several ideas gleaned from the net.

Enjoy!

# Mark D. Salzman    Phone: (206) 253-5542.  #  The more complex the mind,
# Tektronix Inc., P.O. Box 3500, M/S C1-936  #  the greater the need for 
# Vancouver, Washington. 98668               #  the simplicity of play.
# E-MAIL: marks@tekigm2.MEN.TEK.COM          #       James T. Kirk
############################ CUT HERE ############################
echo off
rem STATUS.BAT
rem This sets up a status line using the Prompt command.
rem
rem PROMPT $E[s                Save current cursor position,
rem        $E[0;0H             go to home position,
rem        $E[36;44m           set foreground and background colors,
rem        Path$Q $P           print the current directory,
rem        $E[K                erase rest of line,
rem        $E[0;54H            move cursor to right part of the line,
rem        $D  $T              print date and time,
rem        $E[0m               restore normal colors,
rem        $E[u                restore cursor position,
rem        $N$G                print the usual DOS prompt.
rem
prompt $E[s$E[0;0H$E[36;44mPath$Q $P$E[K$E[0;54H$D  $T$E[0m$E[u$N$G
exit
-- 
# Mark D. Salzman    Phone: (206) 253-5542.  #  The more complex the mind,
# Tektronix Inc., P.O. Box 3500, M/S C1-936  #  the greater the need for 
# Vancouver, Washington. 98668               #  the simplicity of play.
# E-MAIL: marks@tekigm2.MEN.TEK.COM          #       James T. Kirk

iiit-sh@cybaswan.UUCP (Steve Hosgood) (05/24/89)

In article <2219@uwovax.uwo.ca> 13001_6035@uwovax.uwo.ca writes:
>In article <1163@marlin.NOSC.MIL>, jbjones@marlin.NOSC.MIL (John B. Jones) writes:
>> I need a nice date program which I can use at the command line, which
>> won't expect a return or prompt me for a change, and which displays the
>> date and the day of the week.  The output will probably look like this:
>> 
>> 	May 16, 1989 	Tuesday
>What follows is what I think is a more efficient way of displaying
>the time and the date under DOS 3.3.  Somehow I think this is a more
>elegant approach than piping DATE and TIME into FIND.
>
>-----SHOWDT.BAT BEGINS-----CUT HERE-----
> [ .BAT routine deleted ]

All this seems rather over-complicated to me.

I wrote a short routine along the lines of UN*X's 'date' program in Microsoft
'C'. This I called 'date.c' and compiled it to give myself a 'date.exe'. I then
hacked 'command.com' with 'debug' and changed the string 'DATE' to 'DSET' and
'TIME' to 'TSET' in the list of built-in commands. This allows 'date.exe' to
be run.

The source of date.c is at home, but it's pretty much a 6-liner:

# include	<time.h>

main()
{

	printf("%s", asctime(time(( long * ) 0)));
	exit(0);
}

....or something like that. You can fiddle with the string returned by 'asctime'
before printing it if you want to change the format a bit.

I did something similar to give myself a more UN*X-like 'cd' program without
the EVIL backslash seperator that DOS cripples you with. It's amazing how much
more pleasant it is to work on MSDOS after this sort of surgery.

Steve