I'm still having a problem in my Seconds to Period routine for a Dallas 1994 iButton. So much so I can't even get Maxim's sample code to work properly (in theory). I am wondering if there is a maths wiz out there who may be able to point me in the right direction - I've googled and none of the results have helped much in fact they've confused me. The Dallas suggested code for a PC is void SecondsToDate(timedate *td, ulong x) { short tmp,i,j; ulong y; // check to make sure date is not over 2070 (sanity check) if (x > 0xBBF81E00L) x = 0; y = x/60; td->second = (ushort)(x-60*y); x = y/60; td->minute = (ushort)(y-60*x); y = x/24; td->hour = (ushort)(x-24*y); x = 4*(y+731); td->year = (ushort)(x/1461); i = (int)((x-1461*(ulong)(td->year))/4); td->month = 13; do { td->month -= 1; tmp = (td->month > 2) && ((td->year & 3)==0) ? 1 : 0; j = dm[td->month]+tmp; } while (i < j); td->day = i-j+1; // slight adjustment to algorithm if (td->day == 0) td->day = 1; td->year = (td->year < 32) ? td->year + 68 + 1900: td->year - 32 + 2000; } Now with this if I work through for the date 31/12/ 2003 @ 23:59:59 I end up with a year 11 before I get to the 200 adjustment. This is my code after taking year 2000 as the base year. It works apart from the above date where it rolls over to the 32/1/2003 and waits 24 hours before getting to 1st January 2004. Similar problem at end of leap years January starts on the 2nd but the year and month roll over correctly. void secs2period(timecals *pTimeDisp,ulong idata) { ulong temp; ulong m; ulong d; //Max year 31 December 2030 23:59:59, if (idata> 0x3A468DFF) idata=0; temp=idata/60; pTimeDisp->scnd=(idata-60*temp); idata=temp/60; pTimeDisp->min=(temp-60*idata); temp=idata/24; pTimeDisp->hr=(idata-24*temp); idata=4*(temp+731); pTimeDisp->yr=(idata/1461)-2; //1461= 365.25 days * 4years m=temp-(pTimeDisp->yr*365); pTimeDisp->mnth=13; do { pTimeDisp->mnth-=1; temp=(pTimeDisp->mnth > 2) && ((pTimeDisp->yr & 3)==0) ? 1: 0; d=daysofar[timedisp->mnth]+temp; } while (d>m); pTimeDisp->dy=m-d+1; if (pTimeDisp->dy==0) pTimeDisp->dy=1; } I realise that I need to compensate for fractions of a year, I just can't see where. My 'C" compiler for the Pic doesn't allow the casting of structures as written in the Maxim code, and as it's the algorithm that's failing me re-writing it in assembler probably won't get me any further at the moment.. Any help that stops me head banging the wall would be gratefully received. Colin DALLAS COPYRIGHT NOTICE Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. -- cdb, cdb@barnard.name on 31/03/2002 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu