# Date math.. WTF?

• (this didnt make front page so i'm posting here)

Well I was trying to fix a problem our rivals left us in one of our clients Navision system. This dude had functions to calc amount of days between two dates.. (syntax is pascal/delphi like.. Lithuanian var names). Here it goes: [I]

<FONT face="Courier New" size=1>function KalenDienø(data1 : Date;data2 : Date) visokd : Integer
begin
visokd:=0;
IF data1>data2 THEN
EXIT;
dat1:=DATE2DMY(data1,3)*10000+DATE2DMY(data1,2)*100+DATE2DMY(data1,1);
dat2:=DATE2DMY(data2,3)*10000+DATE2DMY(data2,2)*100+DATE2DMY(data2,1);
dat:=dat1 DIV 100;
a:=0;
WHILE(dat<=(dat2 DIV 100)) AND (a<12) DO BEGIN
ld:=KiekDienø(dat DIV 100,dat MOD 100);
IF ((dat1 DIV 100)=dat) OR ((dat2 DIV 100)=dat) THEN BEGIN
IF (dat1 DIV 100)=dat THEN yrakd:=ld-(dat1 MOD 100)+1;
IF (dat2 DIV 100)=dat THEN BEGIN
IF(dat1 DIV 100)=(dat2 DIV 100) THEN yrakd:=yrakd-(ld-(dat2 MOD 100))
ELSE yrakd:=dat2 MOD 100;
END;
END
ELSE yrakd:=ld;
visokd+=yrakd;
IF (dat MOD 100)=12 THEN dat:=((dat DIV 100)+1)*100+1 ELSE dat:=dat+1;
a+=1;
END;
end</FONT>

<FONT face="Courier New" size=1>function KiekDienø(met : Integer;men : Integer) ld : Integer
begin
IF (men MOD 2)=(men DIV THEN ld:=30 ELSE ld:=31;
IF men=2 THEN BEGIN IF (met MOD 4)=0 THEN ld:=29 ELSE ld:=28; END;
end</FONT>

Uhm.. OK? But that's not even the point here.. Navision syntax allows some simple date math, like..

<FONT face="Courier New" size=1>function KalenDienø(data1 : Date;data2 : Date) visokd : Integer
begin</FONT>
<FONT face="Courier New" size=1>exit(data2-data1+1);
end</FONT>

Well, it's never fun to do it easy, eh? [8-)]

<FONT face="Courier New" size=1></FONT>

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.