::: Area #157 (comp.sys.acorn.programmer) Message: #29456 (Read 16 times, has 0 replies, 2072 bytes) Date : Sat Feb 28 01:44:14 1998 From : Jonathan Graham Harston of fidonet#2:254/27 To : All Subject: Re: Calculating dates > Can anyone advise me as to finding the number of days between two dates? > I have the dates in the form of 3 integers (day, month and year). > I have tried with territory manager, but can't get any further than the > difference between the two in UTC format, and this in itself is a bit (a > lot) of a hack :-/ [I may be delayed in replying, I've been wading through the treacle Matthias has been sending] Call the following function with: days%=FNDaysSince(TodaysDate,TodaysMonth,TodaysYear,PastDay,PastMonth,Past Year) REM Return number of days since a past date REM Needs: num%=> buffer at least 28 bytes utc%=> buffer at least 5 bytes DEFFNDaysSince(td%,tm%,ty%,pd%,pm%,py%):LOCAL past% num%!0=0:num%!4=0:num%!8=0:num%!12=0:REM cs, sec, min, hour num%!16=td%:num%!20=tm%:num%!24=ty%: REM this date, month, year SYS "Territory_ConvertOrdinalsToTime",-1,utc%,num%:past%=utc%!1 num%!0=0:num%!4=0:num%!8=0:num%!12=0:REM cs, sec, min, hour num%!16=pd%:num%!20=pm%:num%!24=py%: REM past date, month, year SYS "Territory_ConvertOrdinalsToTime",-1,utc%,num%:=(utc%!1-past%)DIV&83D6 : ...or even: : REM Convert time and date to 5-byte centi-second count since 1st Jan 1900 DEFPROCConvDate(mem%,d%,m%,y%,hr%,mn%,sc%,cs%):IFy%<100:y%=y%+1900 y%=y%MOD400 d%=y%*365.25+m%*30+d%+VALMID$("120112234455",m%,1)+((y%MOD4)=0) d%=d%-((y%-1)DIV100)-(m%>2AND((y%MOD4)=0AND(y%MOD100)<>0ORy%=0))+36493 IFd%>146096:d%=d%-146097 d%=d%*&41EB:mem%!1=d%+d%:d%=((hr%*60+mn%)*60+sc%)*100+cs% ?mem%=d%:mem%!1=mem%!1+d%DIV256:ENDPROC : REM Return number of days since a past date REM Needs: ctrl%>=5 bytes DEFFNDaysSince(td%,tm%,ty%,pd%,pm%,py%):LOCAL past% PROCConvDate(ctrl%,pd%,pm%,py%,0,0,0,0):past%=ctrl%!1 PROCConvDate(ctrl%,td%,tm%,ty%,0,0,0,0):=(ctrl%!1-past%)DIV&83D6 : J.G.Harston (JGH BBC PD Library) 70 Camm Street, Walkley, SHEFFIELD S6 3TR --- ARCbbs RISC OS [1.64á32c] * Origin: Via The Arcade BBS Usenet News Gateway +44 181 655 4412 (2:254/27)