Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Date differences in nawk
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 10th November 02:14
fix_metal
External User
 
Posts: 1
Default Date differences in nawk



Hi all, I'm new posting in this NG. Welcome to myself then
I searched over the web for some infos to do this.
I need a function which would return the difference in days between 2
given dates.
I found a thousand bizarre methods. The most interestings are using GNU
date or GNU awk.
Unfortunatly I'm using a Solaris 8 system which have anything to do
with GNU...
This is my problem. I need to make something under nawk.
An example:
Given dates: (format: DD-MM-YY. I'm Italian, gh
TODAY: 22-09-06
GENERAL DATE: 1-09-06
The function should return 21 days.
Obviously I need something which calculates days over the years. I
already made something similar in the past, in some C formula, but I
can't find it atm....
any hints would be very pleased, since this is kinda urgent....
thanks in advance.
  Reply With Quote


 


2 10th November 02:14
ed morton
External User
 
Posts: 1
Default Date differences in nawk



Just to rule out the easy answer: Why can't you install GNU awk? I use
it on Solaris and it's well worth any small effort to install it. In
this particular instance, the solution's trivial in gawk using it's time
functions and a pain in nawk.

Ed.
  Reply With Quote
3 10th November 02:14
thomas weidenfeller
External User
 
Posts: 1
Default Date differences in nawk


#
# Julian day number from a given date, at midday
#
function julian(y, m, d, u, v, t, w) {
y = int(y + 0)
m = int(m + 0)
d = int(d + 0)

u = m - 3
v = y
if(m <= 2) {
u = m + 9
v = y - 1
}
t = int(v / 100)
w = v % 100
return int((146097 * t) / 4) + int((1461 * w) / 4) + int((153 *
u + 2) / 5) + d + 1721119
}

/TODAY/ {
split($2, t, "-")
td = t[1]
tm = t[2]
ty = 2000 + t[3]
next
}

/GENERAL DATE/ {
split($3, g, "-")
gd = g[1]
gm = g[2]
gy = 2000 + g[3]
print julian(ty, tm, td) - julian(gy, gm, gd)
next
}

/Thomas
  Reply With Quote
4 10th November 02:15
fix_metal
External User
 
Posts: 1
Default Date differences in nawk


Thank you!THis is exactly what I was looking for!
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666