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

Convert Date to a Number

229 views
Skip to first unread message

sKurt

unread,
Sep 30, 2007, 11:25:32 PM9/30/07
to
Hi all,

I'm looking to convert a Date to a Number so I can do Gawk math and get
the difference between two dates.

Computers are a mix of Windows 98 OS and Windows XP OS

I have fdate.exe and if I can't do this 'internally' then I will use
this instead as it does work under the present .BATch.

I am creating a file ONCE so I can check the files date and put it into
a variable %u%, then getting todays date into a variable %l% (L) and
also doing a count at the very beginning of the .BATch to tell me how
many times the program has run. %k%

Taking into account for Win98 '-' and WinXP '/' date seperators

So I get the results;

::+=(01)==============+
::| Count script runs |
::+===================+

@IF EXIST RunCount.DAT goto _1
@>>RunCount.DAT ECHON 0
:_1
@GAWK '{printf"%%s\n",$0+1}' RunCount.DAT>count$$$.tmp
@MOVE /Y count$$$.tmp RunCount.DAT>nul

::+=(02)==================================+
::| Create TODAY.DAT for Initial Date Run |
::+=======================================+

@IF "%j%"=="XP" TITLE CREATE and Parse TODAY.DAT

@ECHON set u=>tmp$$.bat

@IF EXIST TODAY.DAT GOTO :_CUSP

@>>TODAY.DAT ECHO ONE TIME RUN - DO NOT ERASE

:_CUSP

@IF "%j%"=="XP" DIR TODAY.DAT | FIND /I "TODAY.DAT" | CUT 1 10
>>tmp$$.bat


::+==( Change y2 to y6 for -07 to -2007 )==+

@IF "%j%"=="98" DIR TODAY.DAT | FIND /I "TODAY.DAT" | CUT 29 36 | SED15
"s/-%y2%/-%y6%/">>tmp$$.bat

@CALL tmp$$.bat>NUL
@DEL tmp$$.bat>NUL

@>>PushPos.LOG ECHO Initial Day of Run = %u%
@ECHO.>>PushPos.LOG

::+=(03)===================================+
::| Compare Initial Date with Release Date |
::+========================================+

@IF "%j%"=="XP" TITLE COMPARE dates

@ECHON set l=>tmp$$.bat

@IF "%j%"=="XP" FDATE /Fdif /a%u% /b%m6%/%d6%/%y6%>>tmp$$.bat

@IF "%j%"=="98" FDATE /Fdif /a%u% /b%m6%-%d6%-%y6%>>tmp$$.bat

@CALL tmp$$.BAT>NUL
@DEL tmp$$.bat>NUL

@>>PushPos.LOG ECHO Total Days since Initial Date = %l%
@ECHO.>>PushPos.LOG

::+=(04)======================================+
::| Subtract Number of runs from initial date |
::+===========================================+

@IF "%j%"=="XP" TITLE Subtract NUMBER of runs

@ECHON set w=>tmp$$.bat

@GAWK 'BEGIN{printf %l% - %k%}'>>tmp$$.bat

@CALL tmp$$.bat>NUL
@DEL tmp$$.bat>NUL

@>>PushPos.LOG ECHO Difference Number of Runs and Initial Date = %w%
@ECHO.>>PushPos.LOG

::+==================================================+::

I thought about a Gregorian date to Julian date, however, I don't think
that is really what I am looking for. Or even Epoch time from
01/01/1970 and using strftime("%c",systime()) to convert ticks from
dates.


I'd like to convert the DATE to a NUMBER of the year? i.e.;

JANUARY 01, 2007 is DAY NUMBER 1
JANUARY 31, 2007 is DAY NUMBER 31
OCTOBER 01, 2007 is DAY NUMBER 274
DECEMBER 31, 2007 is DAY NUMBER 365

I could put together an awful kludge of:

@IF "%u%"=="10/01/%y6%" SET u=274
@IF "%u%"=="10/02/%y6%" SET u=275
@IF "%u%"=="10/03/%y6%" SET u=276

and so on, but that would be at least 365 lines for TODAY.DAT %u%

and another 365 lines for Today's Date %l%

And also to factor in Leap year

Thanks for any help

sKurt

--

Message has been deleted

sKurt

unread,
Oct 1, 2007, 1:05:34 AM10/1/07
to
Guy wrote:

> sKurt wrote:
>
> > I'm looking to convert a Date to a Number so I can do Gawk math
> > and get the difference between two dates.
> >
>

> Not to steer you in another direction. But if you are able to use
> GAWK in your computing environment you may want to look at Nowminus.
> <www.merlyn.demon.co.uk>

Thanks, I have been to your site before in my never ending attempt at
creating/improving .BATch files ;) However, while I am sure your
nowminus program does what I want, the present .BATch file has the
ability to do what I need by using the FDATE.EXE program, I was hoping
that I wouldn't have to upload yet another program to the masses that
are using my .BATch, and if it came to me having to upload yet another
ancillery program, it would be the FDATE.EXE.

Unless of course your NOWMINUS program does everything and more than
FDATE! ;)

thanks for your suggestion I will be reading the differences between
both and decide which I might have to upload.

sKurt

--

Todd Vargo

unread,
Oct 1, 2007, 1:12:37 AM10/1/07
to
sKurt wrote:
> Hi all,
>
> I'm looking to convert a Date to a Number so I can do Gawk math and get
> the difference between two dates.
>
> Computers are a mix of Windows 98 OS and Windows XP OS
>
> I have fdate.exe and if I can't do this 'internally' then I will use
> this instead as it does work under the present .BATch.
>
> I am creating a file ONCE so I can check the files date and put it into
> a variable %u%, then getting todays date into a variable %l% (L) and
> also doing a count at the very beginning of the .BATch to tell me how
> many times the program has run. %k%
>
> Taking into account for Win98 '-' and WinXP '/' date seperators
>
snip...

>
> I thought about a Gregorian date to Julian date, however, I don't think
> that is really what I am looking for. Or even Epoch time from
> 01/01/1970 and using strftime("%c",systime()) to convert ticks from
> dates.
>
>
> I'd like to convert the DATE to a NUMBER of the year? i.e.;
>
> JANUARY 01, 2007 is DAY NUMBER 1
> JANUARY 31, 2007 is DAY NUMBER 31
> OCTOBER 01, 2007 is DAY NUMBER 274
> DECEMBER 31, 2007 is DAY NUMBER 365
>
> I could put together an awful kludge of:
>
> @IF "%u%"=="10/01/%y6%" SET u=274
> @IF "%u%"=="10/02/%y6%" SET u=275
> @IF "%u%"=="10/03/%y6%" SET u=276
>
> and so on, but that would be at least 365 lines for TODAY.DAT %u%
>
> and another 365 lines for Today's Date %l%
>
> And also to factor in Leap year
>
>
>
>
>
> Thanks for any help

This task would be better suited for WSH/VBScript which is an installed
component on Windows 98 and newer Windows systems.

BTW, counting the number of runs is a plain count that does not involve date
calculations. Counting the number of days since some initial date does not
require calculating the day-of-year or factoring in Leap Year either.

The following VBScript code shows how you could capture these three values.
Please note that further discussion regarding VBScript code should be
directed to a WSH/VBScript specific group.

' Run counter = 0
' Line above must be the first line in script!
ini = #Aug 10, 2007# 'a randomly selected initial date
d = Date 'Capture Today's date
doy = int(d - cdate("1/1/" & Year(d))) + 1
lapsed = d - ini 'Days lapsed since initial date

Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Wscript.ScriptFullName, ForReading)
arrVBS = Split(f.ReadAll, vbCRLF)
count = Mid(arrVBS(0), 17) + 1
arrVBS(0) = Left(arrVBS(0), 16) & count
Set f = fso.OpenTextFile(Wscript.ScriptFullName, ForWriting)
f.Write Join(arrVBS, vbCRLF)

Wscript.Echo "DOY=" & doy & vbCRLF & _
"Days lapsed since " & ini & " = " & lapsed & vbCRLF & _
"Number of times script has run = " & count & vbCRLF & _
"These are three unrelated values."


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

Ted Davis

unread,
Oct 1, 2007, 8:45:51 AM10/1/07
to
On Mon, 01 Oct 2007 03:25:32 +0000, sKurt wrote:

> I'm looking to convert a Date to a Number so I can do Gawk math and get
> the difference between two dates.

gawk has a function to do this: mktime(). The current date and time are
always available in gawk as systime(). Both functions produce a number
corresponding to the number of seconds since 0 January 1970 for the date
in question. See gawk.hlp -> Index -> Time functions.

--
T.E.D. (tda...@umr.edu)

sKurt

unread,
Oct 1, 2007, 10:24:24 AM10/1/07
to
Ted Davis wrote:

Thanks, I received a bit of help from the comp.lang.awk group as;

gawk 'BEGIN{print strftime("%j",mktime("2007 10 01 00 00 00"))}'

I haven't dug into that yet as it is early, however, I think the

2007 10 01 would be today Oct. 01, 2007 and the 00 00 00 is the time?

it says to create the mktime() string us split() so I have to research
split() and how to make the 10/01/2007 into 2007 10 01 00 00 00

sKurt

--

Ted Davis

unread,
Oct 1, 2007, 3:55:11 PM10/1/07
to
On Mon, 01 Oct 2007 14:24:24 +0000, sKurt wrote:

> it says to create the mktime() string us split() so I have to research
> split() and how to make the 10/01/2007 into 2007 10 01 00 00 00

String = "10/01/2007"
split( String, Array, "/" )
String = Array[ 1 ] " " Array[ 2 ] " " Array[ 3 ] " 00 00 00"

--
T.E.D. (tda...@umr.edu)

sKurt

unread,
Oct 1, 2007, 5:57:06 PM10/1/07
to
Ted Davis wrote:

so I would do

String = %v% (where %v% is the variable for the date found)

gawk split(string, array, "/") where does the array come in?

gawk String = Array[ 1 ] " " Array[ 2 ] " " ....... etc.,

gives the number 274 for the date found if 10/01/2007?

Thanks...
sKurt


--

sKurt

unread,
Oct 1, 2007, 6:16:34 PM10/1/07
to
Todd Vargo wrote:


I understand that it is a plain count. What I was aiming for was a kind
of poor man's check to see if the number of times the program has run
since the initial count. And if it matches the days of run as it should
only run once a day i.e.;

Initial date of run (09/01/2007) - Today's Date (10/01/2007) = 30

Number of times the program has run since Initial date of run = 30

( or whatever ) so the difference of runs and initial date tell me to
some degree if the program ran more than once in a day, also I have a
log file that tells me when it starts and stops so when the count comes
back we can go to the site and get the log if necessary.

And yes, I probably don't need leap year if I am not coverting
(10/01/2007) to the Day of Year (274)

Thanks again! I'll see where/how I can put this together in my mixed OS

sKurt
--

Ted Davis

unread,
Oct 1, 2007, 9:20:01 PM10/1/07
to
On Mon, 01 Oct 2007 21:57:06 +0000, sKurt wrote:

> Ted Davis wrote:
>
>> On Mon, 01 Oct 2007 14:24:24 +0000, sKurt wrote:
>>
>> > it says to create the mktime() string us split() so I have to research
>> > split() and how to make the 10/01/2007 into 2007 10 01 00 00 00
>>
>> String = "10/01/2007"
>> split( String, Array, "/" )
>> String = Array[ 1 ] " " Array[ 2 ] " " Array[ 3 ] " 00 00 00"
>
> so I would do
>
> String = %v% (where %v% is the variable for the date found)
>
> gawk split(string, array, "/") where does the array come in?

It is good practice to capitolize user variables so that they are not
all one case - this avoids any possible conflict with built-in variables
which are all one or the other.

As explained in gawk.hlp, the array contains the fields separated by
split, in order. "Array" is the name of an array. I also often use
"Scratch" and "Arr".

>
> gawk String = Array[ 1 ] " " Array[ 2 ] " " ....... etc.,
>
> gives the number 274 for the date found if 10/01/2007?
>

I can't make heads ot tails of that - I think you may have gotten an error
code instead of a result, but it's so garbled it's not possible to know
what you did.

Oops

String = Array[ 1 ] " " Array[ 2 ] " " Array[ 3 ] " 00 00 00"

should be
String = Array[ 3 ] " " Array[ 1 ] " " Array[ 2 ] " 00 00 00"

This is my test program (awktest.awk) and screen dump.

BEGIN{


String = "10/01/2007"
split( String, Array, "/" )

String = Array[ 3 ] " " Array[ 1 ] " " Array[ 2 ] " 00 00 00"
print String
}

e:\myfiles>awk -fawktest.awk


2007 10 01 00 00 00

--
T.E.D. (tda...@umr.edu)

sKurt

unread,
Oct 2, 2007, 12:30:17 AM10/2/07
to
Ted Davis wrote:


>
> It is good practice to capitolize user variables so that they are not
> all one case - this avoids any possible conflict with built-in
> variables which are all one or the other.
>
> As explained in gawk.hlp, the array contains the fields separated by
> split, in order. "Array" is the name of an array. I also often use
> "Scratch" and "Arr".
>
> >
> > gawk String = Array[ 1 ] " " Array[ 2 ] " " ....... etc.,
> >
> > gives the number 274 for the date found if 10/01/2007?
> >
>
> I can't make heads ot tails of that - I think you may have gotten an
> error code instead of a result, but it's so garbled it's not possible
> to know what you did.
>
> Oops
> String = Array[ 1 ] " " Array[ 2 ] " " Array[ 3 ] " 00 00 00"
> should be
> String = Array[ 3 ] " " Array[ 1 ] " " Array[ 2 ] " 00 00 00"
>
> This is my test program (awktest.awk) and screen dump.
>
> BEGIN{
> String = "10/01/2007"
> split( String, Array, "/" )
> String = Array[ 3 ] " " Array[ 1 ] " " Array[ 2 ] " 00 00 00"
> print String
> }
>
> e:\myfiles>awk -fawktest.awk
> 2007 10 01 00 00 00

Thanks Ted, I will lean more to upper case variables for the future.

This closer?

gawk 'BEGIN{print strftime("%j",mktime("2007 10 01 00 00 00"))}'

If possible pass DOS batch variables to awk using awk variables; I
think in a DOS command window it might be called as

gawk -v d=%u% -v d2=%v% -f fff.awk

for two DOS variables %u% and %v%. The file fff.awk may contain, e.g.

BEGIN {
split(d,a,"/")
x = mktime(a[3]" "a[1]" "a[2]" 0 0 0")
i = strftime("%j",x)

split(d2,b,"/")
y = mktime(b[3]" "b[1]" "b[2]" 0 0 0")
j = strftime("%j",y)

print i - j
}


From help in comp.lang.awk Janis


Gonna have to sit down and study this and Todd's and Billious'
suggestions with yours and Janis' Phew, this is like school ;)

sKurt

--

Mike Jones

unread,
Oct 2, 2007, 4:21:55 AM10/2/07
to


I wrote (way back) a simple assembler program called Onceaday, which I
invoked in the autoexec, it saved the current date in itself and checked
on running if the current date was the same, if so it exited; if not it
updated the saved date (so requires write access) and set the errorlevel.
Unfortunately I seem to have mislaid the source, but here's the a debug
dump:

EB 2 9 2 E8 5A 0 8B D7 6 1F B8 2 3D CD 21 8B D8 E 1F B9 4 0 BA 0 1 B4 3F
CD 21 91 3B C1 74 3 F9 EB 1 F8 B4 2A CD 21 B0 0 3B 16 2 1 74 24 89
16 2 1 B0 1 50 33 C9 33 D2 B0 0 B4 42 CD 21 B9 4 0 BA 0 1 B4 40 CD 21
91 3B C1 74 3 F9 EB 1 F8 50 B4 3E CD 21 58 B4 4C CD 21 B9 0 80 A1 2C 0
8E C0 33 FF 33 C0 F2 AE 26 38 5 75 F9 'GGG' C3


I expect it could be made smaller; Herbert are you there :-)

Herbert Kleebauer

unread,
Oct 2, 2007, 7:31:20 AM10/2/07
to
Mike Jones wrote:

> I wrote (way back) a simple assembler program called Onceaday, which I
> invoked in the autoexec, it saved the current date in itself and checked
> on running if the current date was the same, if so it exited; if not it
> updated the saved date (so requires write access) and set the errorlevel.
> Unfortunately I seem to have mislaid the source, but here's the a debug
> dump:
>
> EB 2 9 2 E8 5A 0 8B D7 6 1F B8 2 3D CD 21 8B D8 E 1F B9 4 0 BA 0 1 B4 3F
> CD 21 91 3B C1 74 3 F9 EB 1 F8 B4 2A CD 21 B0 0 3B 16 2 1 74 24 89
> 16 2 1 B0 1 50 33 C9 33 D2 B0 0 B4 42 CD 21 B9 4 0 BA 0 1 B4 40 CD 21
> 91 3B C1 74 3 F9 EB 1 F8 50 B4 3E CD 21 58 B4 4C CD 21 B9 0 80 A1 2C 0
> 8E C0 33 FF 33 C0 F2 AE 26 38 5 75 F9 'GGG' C3

Sorry, but this program doesn't impress me. Here a disassembly with
some comments:

@=$100
_0100: br.b _0104
_0102: dc.b 9,2 ; day,month
_0104: bsr.w _0161 ; get pointer to program name
move.w r6,r1
move.w s1,-(sp)
move.w (sp)+,s0 ; seg for env.
move.w #$3d02,r0
trap #$21 ; open for read/write
move.w r0,r3 ; handle
move.w s6,-(sp)
move.w (sp)+,s0 ; restor DS
move.w #$0004,r2
move.w #_0100,r1
move.b #$3f,m0
trap #$21 ; read 4 bytes (why?? nothing new in the file!!!)
exg.w r0,r2 ; why???
cmp.w r2,r0 ; 4 bytes read?
beq.b _0126 ; yes
bset.w #0,sr ; no: set carry flag (why? never used!!!)
br.b _0127
_0126: bclr.w #0,sr ; not necessary, carry already clear
_0127: move.b #$2a,m0
trap #$21 ; get date
move.b #$00,r0 ; errorlevel=0: stored date = current date
cmp.w _0102,r1 ; month/day
beq.b _0157
move.w r1,_0102 ; store new mont/day
move.b #$01,r0 ; errorlevel=1: stored date != current date
move.w r0,-(sp) ; errorlevel=1 (never poped from the stack!!!)
eor.w r2,r2
eor.w r1,r1
move.b #$00,r0
move.b #$42,m0
trap #$21 ; seek to start of file
move.w #$0004,r2
move.w #_0100,r1
move.b #$40,m0
trap #$21 ; write first 4 bytes
exg.w r0,r2 ; r0=4
cmp.w r2,r0
beq.b _0156 ; all 4 bytes written
bset.w #0,sr ; set carry if not (never used!!!)
br.b _0157
_0156: bclr.w #0,sr ; not necessary, carry already clear
_0157: move.w r0,-(sp) ; r0=0 if same date r0=4 otherwise
move.b #$3e,m0
trap #$21 ; close file
move.w (sp)+,r0 ; errorlevel 0 or 4 (why 4 ????)
move.b #$4c,m0
trap #$21 ; exit

_0161: move.w #$8000,r2
move.w $002c,r0 ; segment to environment
move.w r0,s1
eor.w r6,r6
eor.w r0,r0
_016d: repne_r2 cmp.b (r6.w)+-{s1},r0
cmp.b r0,(r6.w){s1} ; end of env.
bne.b _016d ; no
inc.w r6 ; skip null
inc.w r6 ; skip next word
inc.w r6 ; better check if it's 1
rts.w ; r6 ponter to program path/name

Herbert Kleebauer

unread,
Oct 2, 2007, 8:14:24 AM10/2/07
to
sKurt wrote:

> I understand that it is a plain count. What I was aiming for was a kind
> of poor man's check to see if the number of times the program has run
> since the initial count. And if it matches the days of run as it should
> only run once a day i.e.;
>
> Initial date of run (09/01/2007) - Today's Date (10/01/2007) = 30
>
> Number of times the program has run since Initial date of run = 30
>
> ( or whatever ) so the difference of runs and initial date tell me to
> some degree if the program ran more than once in a day, also I have a
> log file that tells me when it starts and stops so when the count comes
> back we can go to the site and get the log if necessary.

If you mean an "exe" with the term "program", then I don't think a batch
will be able to check how often the program was executed (that has to
do the exe itself). If "program" is a batch program, why not include
three simple lines:

if exist _log.bat call _log.bat
echo set last=%date%>_log.bat
if [%last%]==[%date%] echo %date%: batch executed more than once>>_log.txt


In DOS/Win9x you have first to set %date% either with batch code like

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo set date=%%2 >call._1_
dir call._1_ |find "_1_" >_2_.bat
ren call._1_ _1_.bat
call _2_.bat
del _1_.bat
del _2_.bat
echo "%date%"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

or better use a small com program like:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>dat.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>dat.com
echo LisqGH`wpuubg@@{{zGgWg@KoG?w?RgBgOG}s?M_ry?hNx@G@z?G`L?Kuu>>dat.com
echo BND@qAHoo_BBFSB?p{rIcP_sdDs`cTs=dP0>>dat.com
dat.com >dat.bat
call dat.bat
echo %date%
del dat.com
del dat.bat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

; write set date=yymmdd >stdout

@=$100

move.b #$2a,m0 ; get date function
trap #$21 ; call dos
move.w r2,r0 ; year
divu.b c100,m0|r0 ; last 2 digits -> m0
lsr.w #8,r0 ; last 2 digits -> r0
move.w #buf1,r3 ; adr of write buffer
bsr.w _500 ; output in write buffer
move.b m1,r0 ; month
bsr.w _500 ; output in write buffer
move.b r1,r0 ; day
bsr.w _500 ; output in write buffer

move.b #$40,m0 ; write function
move.w #buf,r1 ; adr of write buffer
move.w #9+6,r2 ; write 6 char: yymmdd
move.w #1,r3 ; stdout
trap #$21 ; call dos
rts.w

_500: divu.b c10,m0|r0 ; r0=high m0=low digit
add.w #'00',r0 ; convert to ascii
move.w r0,(r3.w) ; copy in write buffer
inc.w r3 ; inc write pointer
inc.w r3 ; inc write pointer
eor.w r0,r0 ; clear r0
rts.w

c100: dc.b 100 ; constant 100
c10: dc.b 10 ; constant 10

buf: dc.b 'set date='
buf1:

Ted Davis

unread,
Oct 2, 2007, 8:55:01 AM10/2/07
to
On Tue, 02 Oct 2007 04:30:17 +0000, sKurt wrote:

>
> This closer?
>
> gawk 'BEGIN{print strftime("%j",mktime("2007 10 01 00 00 00"))}'

Obviously, you have not tried that: it's Unix command line syntax and
doesn't work in Windows/DOS.

gawk "BEGIN{print strftime(\"%j\",mktime(\"2007 10 01 00 00 00\"))}"

is Windows/DOS syntax.


>
>
>
> If possible pass DOS batch variables to awk using awk variables; I think
> in a DOS command window it might be called as
>
> gawk -v d=%u% -v d2=%v% -f fff.awk
>
> for two DOS variables %u% and %v%. The file fff.awk may contain, e.g.
>
> BEGIN {
> split(d,a,"/")
> x = mktime(a[3]" "a[1]" "a[2]" 0 0 0") i = strftime("%j",x)
>
> split(d2,b,"/")
> y = mktime(b[3]" "b[1]" "b[2]" 0 0 0") j = strftime("%j",y)
>
> print i - j
> }
> }
> }
> From help in comp.lang.awk Janis
>
>
> Gonna have to sit down and study this and Todd's and Billious'
> suggestions with yours and Janis' Phew, this is like school ;)
>
> sKurt

--
T.E.D. (tda...@umr.edu)

Ted Davis

unread,
Oct 2, 2007, 9:10:37 AM10/2/07
to
On Tue, 02 Oct 2007 04:30:17 +0000, sKurt wrote:

Oops, I missed the last part.

> If possible pass DOS batch variables to awk using awk variables; I think
> in a DOS command window it might be called as
>
> gawk -v d=%u% -v d2=%v% -f fff.awk

You didn't test that either. In general, you need "" around the value
part. But there is no need to pass environment variables on the command
line since the program can read them directly.


>
> for two DOS variables %u% and %v%. The file fff.awk may contain, e.g.
>
> BEGIN {
> split(d,a,"/")

split(ENVIRON[ "u" ],a,"/")

> x = mktime(a[3]" "a[1]" "a[2]" 0 0 0") i = strftime("%j",x)
>
>

> split(d2,a,"/")

split(ENVIRON[ "v" ],b,"/")
Assuming u and v are lower case vaeriable names - ENVIRON is case
sensitive.

> y = mktime(b[3]" "b[1]" "b[2]" 0 0 0") j = strftime("%j",y)
>
> print i - j
> }
> }
> }
> From help in comp.lang.awk Janis

I noticed, but didn't comment. Keep in mind that almost everybody there
is a Unix/Linux programmer/user - there are major differences in how gawk
has to be handled in WIndows, and some of the functionality simply doesn't
work in Windows.

>
>
> Gonna have to sit down and study this and Todd's and Billious'
> suggestions with yours and Janis' Phew, this is like school ;)

--
T.E.D. (tda...@umr.edu)

sKurt

unread,
Oct 2, 2007, 9:56:58 AM10/2/07
to
Ted Davis wrote:


Yes I've noticed that everything is mostly 'nix based and while it
doesn't work in DOS/WIN, I am hoping the basic syntax works enough
where I can tweak it or at the very least take the idea and see the
corresponding DOS/WIN way to do it.

I did try the above and it did give syntax errors and with the many
suggestions today I will have the time to try each and see which works
in my environment.

Thanks for the help!

sKurt

--

Mike Jones

unread,
Oct 2, 2007, 9:57:13 AM10/2/07
to
Herbert Kleebauer wrote:
> Mike Jones wrote:
>
>> I wrote (way back) a simple assembler program called Onceaday, which I

[Disassembly to a Herbert's preferred syntax snipped]


Like I said, I'm sure it could be improved, I was still learning asm at
the time. The CLC/STC was in a fileio macro so not needed here, as you
say, there's no need to Read the date from within the program! The 0161
rtn was stolen code to get the program name.

I probably went with errorlevel 4 as this was a value I could reuse!

OK you made me dig out the code and rewrite it: 120 bytes down to 74!

debug dump:

EB 2 0 0 B9 0 80 A1 2C 0 8E C0'3'FF'3'C0 F2 AE 26 38 5 75 F9 'GGG'
8B D7 6 1F B8 1 3D CD 21 8B D8 E 1F B4 2A CD 21 B0 0 3B 16 2 1 74
E 89 16 2 1 BA 0 1 B9 4 0 B4 40 CD 21 50 B4 3E CD 21 58 B4 4C CD 21


MASM syntax:

; writes date to this prog, rc=4 if changed
.radix 16
code segment
org 2ch
env_str dw ?
org 100h
assume cs:code,ds:code

top: jmp short start
today_dt dw ?
save_lth equ $-offset top
start:
; call whoami
;whoami proc near
; on exit:
; es:di pts to ascz prog name as EXECed [drv path] + .ext
; ax corrupted
mov cx,8000h ; 32k max!
mov ax,word ptr [env_str]
mov es,ax
xor di,di
xor ax,ax ; search for dw 0
; es:di
notha:
repnz scasb
cmp byte ptr es:[di],al
jnz notha
; got 2 asczs
inc di ; ascz
inc di ; skip word count
inc di ; & ascz
;OR add di,3
; ret
;whoami endp
mov dx,di ; fn in dx for open
push es
pop ds ; point ds to env str fn
; open_file for_read_write
mov ax,03D01h
int 21h
mov bx,ax ; set up for read, close
push cs
pop ds ; restore ds to cs
; what's today?
mov ah,02Ah
int 21
mov al,0 ; rc zero if same
cmp dx,word ptr [today_dt]
je same
mov word ptr [today_dt],dx
mov dx,offset top
mov cx,save_lth ; jp +date
; write_rec ; from top of program only 4 reqd
mov ah,040h
int 21h
same:
push ax ; save rc
mov ah,03Eh ; close
int 21h
pop ax
mov ah,04Ch ; exit
int 21h

code ends

end

Dr J R Stockton

unread,
Oct 2, 2007, 12:30:53 PM10/2/07
to
In alt.msdos.batch message <pan.2007.10.01....@umr.edu>,
Mon, 1 Oct 2007 07:45:51, Ted Davis <tda...@umr.edu> posted:

One who is careful enough to use "since 0 Jan" for a count starting at
Jan 1.000 should for consistency also state whether that is GMT/UTC or
local standard time or local time (it was summer in Australia, and
Summer Time in the UK, then). If it's said to be UTC, the GAWK ought to
handle Leap Seconds.

Be very aware that about 0.5% of days, in many places, are 24+-1 hours
long in LCT.

It may be possible and helpful to work with the time-of-day forced to
about noon, and to round day-differences.

Be careful with DOS ports of GAWK --- At least one, AFAIR, had the US
DST rules built in and ignored TZ except for obtaining the Standard
Offset. That of course could be annoying for much of the rest of the
world, using different change dates. Now the USA has changed its change
dates, ho ho ho !!.


If the OP wants to program date to daycount himself, he should review
the Zeller pages on my site, etc.

But, given the stated OSs, I'd suggest Javascript or VBScript under WSH,
for which news:microsoft.* has newsgroups.

--
(c) 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.

Mike Jones

unread,
Oct 4, 2007, 2:24:04 AM10/4/07
to
Mike Jones wrote:
> Herbert Kleebauer wrote:
>> Mike Jones wrote:
>>
>>> I wrote (way back) a simple assembler program called Onceaday, which I
>
> [Disassembly to a Herbert's preferred syntax snipped]
>
>
> Like I said, I'm sure it could be improved, I was still learning asm at
> the time. The CLC/STC was in a fileio macro so not needed here, as you
> say, there's no need to Read the date from within the program! The 0161
> rtn was stolen code to get the program name.
>
> I probably went with errorlevel 4 as this was a value I could reuse!
>
> OK you made me dig out the code and rewrite it: 120 bytes down to 74!
>
>
Moved file manipulation later; no need if the saved date is the same as
current.

.radix 16
code segment
org 2ch
env_str dw ?
org 100h
assume cs:code,ds:code

top: jmp short start
today_dt dw ?
save_lth equ $-offset top
start:

; what's today?
mov ah,02Ah
int 21
mov al,0 ; rc zero if same
cmp dx,word ptr [today_dt]

je alldone


mov word ptr [today_dt],dx

;; update saved date


; call whoami
;whoami proc near
; on exit:

; es:di pts to ascz prog name (ucase) as EXECed [drv path] +

.ext
; ax corrupted
mov cx,8000h ; 32k max!
mov ax,word ptr [env_str]
mov es,ax
xor di,di
xor ax,ax ; search for dw 0
; es:di
notha:
repnz scasb
cmp byte ptr es:[di],al
jnz notha
; got 2 asczs
inc di ; ascz
inc di ; skip word count
inc di ; & ascz
;OR add di,3
; ret
;whoami endp
mov dx,di

push es
pop ds ; point ds to env str fn
; open_file for_read_write
mov ax,03D01h

push ax ; set rc 1


int 21h
mov bx,ax ; set up for read, close
push cs
pop ds ; restore ds to cs

mov dx,offset top
mov cx,save_lth ; jp +date
; write_rec ; from top of program only 4 reqd
mov ah,040h
int 21h

mov ah,03Eh ; close
int 21h
pop ax

alldone:

sKurt

unread,
Oct 4, 2007, 2:48:09 AM10/4/07
to
Mike Jones wrote:

Bang Zoom! way over my head. I played with basic Assembler using IBM
ASSEMBLER 1.0 and thought, while efficient, what a headache. props to
those who know it well.


sKurt
--

sKurt

unread,
Oct 4, 2007, 2:51:38 AM10/4/07
to
Ted Davis wrote:

P.S. The Gawk 3.1.3 code didn't like the single quotes ' it was OK
when I changed them to double ", however things like this statement
went funny

gawk "BEGIN{printf"%%s\n",

it didn't like the "%%s\n" either with single/double or No quotes

so I have to see what works and what I need to fix before I change from
2.16 to 3.1.3 and are able to use mktime()

sKurt

--

Ted Davis

unread,
Oct 4, 2007, 9:16:38 AM10/4/07
to

That's garbage in any OS. All double quotes inside double quotes must be
escaped with backslashes: gawk "BEGIN{printf\"%%s\n\",

Sometimes this becomes troublesome, in which case I use octal escape codes
for the problem characters (\042 for "). I have a list at
<http://gearbox.maem.umr.edu/batch/CharCodes1.html>.

--
T.E.D. (tda...@umr.edu)

sKurt

unread,
Oct 4, 2007, 10:57:13 AM10/4/07
to
Ted Davis wrote:


> >
>
> That's garbage in any OS. All double quotes inside double quotes
> must be escaped with backslashes: gawk "BEGIN{printf\"%%s\n\",
>
> Sometimes this becomes troublesome, in which case I use octal escape
> codes for the problem characters (\042 for "). I have a list at
> <http://gearbox.maem.umr.edu/batch/CharCodes1.html>.


Yes, I understand that, however, what I don't understand is why it
worked before?

@IF EXIST RunCount.DAT goto _1

@>>RunCount.Dat ECHO 0


:_1
@GAWK '{printf"%%s\n",$0+1}' RunCount.DAT>count$$$.tmp

@MOVE /Y count$$$.tmp RunCount.DAT>NUL

Works with GAWK 2.15 Patch 6 but gives errors on the single quotes on
Gawk 3.1.3

If I change the single quotes to double quotes, then it complains on the
"%%s\n" part of the code, changing that to single quotes gives

^ syntax error
^ backslash not last character on line

When I did this

GAWK "{printf \"%%s\n\",$01+1}" RunCount.DAT>count$$$.tmp

it produced the output;

%s

I will put it all as one and see what happens to that.

Thanks for the hints

sKurt


That works! so the \ backslash delimiters may need to be added to all
the code in order for me to start using 3.1.3. Still don't understand
why it changed from 2.15 to 3.1.3 where it worked then didn't, meh...

--

0 new messages