Newbie: Subtracting Dates

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Dec 5 16:53:09 EST 2002


mowestusa fed this fish to the penguins on Thursday 05 December 2002 
11:39 am:

> 
> It seems that programing date addition and subtraction is harder than
> I
> realized.  I'm wondering if Python offers anything to help with this. 
> I would also like to know of some web resources that I could read
> about
> programming and working with dates.  Excel and other spread sheets do
> it all
> of the time, so I know that it can be done.  Also I could think of
> lots of applications once I understand this basic concept like: a
> birthday reminder, bill payment reminder, financial planning once one
> knows the time frame, and others.
>
        There's a whole book on the subject (I think it may be in a second 
edition by now).

        Calendrical Calculations
        Nachum Dershowitz & Edward M. Reingold
        1997 Cambridge University Press


        Probably out of print, but one I found useful.

        Practical Astronomy with Your Calculator (3rd ed)
        Peter Duffett-Smith
        1988 Cambridge University Press


        Normally I'd convert (on the calculator) an input in the form of 
yyyy.mmDDddd to JD. For your example, using my programmable calculator 
(HP, hence the RPN sequence, with the functions from Duffett-Smith 
loaded):

2002.1206 JD
1900.0101 JD
-

give 37694 days.

365.25 /

gives 102.926762491 years

or 102 years, 11.121149892 days

        I don't want to consider math to determine how many months that 
fraction is -- is a month 30 days or 30.4375 days?

(the latter value gives) 102 years, 11 months, and 3.68749983775 days 
(you crossed two century years, and the leap year rules are such that 
1900 did not have a leap day).


        Oh, that relies upon the J2000 definition for the length of the year; 
I'd have to dig a bet to find the proper values for the previous 
standard (B1900).


-- 
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




More information about the Python-list mailing list