Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.081 X-Spam-Evidence: '*H*': 0.84; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.06; 'steve': 0.09; "person's": 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'things,': 0.09; 'wrong,': 0.09; 'python': 0.11; 'calculator': 0.16; 'hayes': 0.16; 'illustrates': 0.16; 'when,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'python?': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; "i've": 0.25; 'script': 0.25; 'received:(smtp server)': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'usually': 0.31; 'gary': 0.31; 'anyone': 0.31; 'worked': 0.33; 'url:python': 0.33; "can't": 0.35; 'except': 0.35; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'dates': 0.36; 'done': 0.36; 'url:org': 0.36; 'too': 0.37; 'easily': 0.37; 'sometimes': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'simple,': 0.60; 'matter': 0.61; 'course': 0.61; 'simple': 0.61; "you've": 0.63; 'pick': 0.64; 'more': 0.64; 'finally': 0.65; 'charset:windows-1252': 0.65; 'worth': 0.66; 'research,': 0.68; 'records,': 0.69; 'programs,': 0.74; 'age': 0.80; 'hand': 0.80; 'age.': 0.84; 'census': 0.84; 'kiss': 0.84; 'mention.': 0.84; 'much,': 0.84; 'subject:Using': 0.84; 'understand,': 0.84; 'birth': 0.91; 'average': 0.93 X-Virus-Scanned: OK X-Sender-Id: gary.herron@islandtraining.com Date: Fri, 21 Nov 2014 00:50:13 -0800 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Using Python for date calculations References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416560232 news.xs4all.nl 2906 [2001:888:2000:d::a6]:48944 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81184 On 11/21/2014 12:35 AM, Steve Hayes wrote: > I've finally found a use for Python. > > When, in the course of my genealogy research, I look at census or burial > records, I often want to work out a person's date of birth from their age. > It's a simple matter of mental arithmetic, but I sometimes get it wrong, and > mislead myself. There are calculators and date calculation programs, but they > are usually too complicated and try to do too much, so by the time you've > worked out what to do it takes much longer. > > This Python script does it for me. > > year = input("Year: ") > age = input("Age: ") > born = year-age > print 'Year of birth:', born > > It's so simple, so elementary, that it's not really worth writing about, > except for the fact that it illustrates the KISS principle. > > It is sometimes better to have a simple program that does one thing well than > a complex one that does lots of things, but none of them very efficiently. > > The average hand calculator can do the same job, but you have to pick it up > and put it down, and you can't easily see if you've made a typo. > > Having said that, however, yes, I would perhaps like to use Python for more > complicated date processing routines, namely to convert the kinds of dates > produced by genealogy programs to a simple yyyy-mm-dd that computer database > programs can understand, so that "Abt May 1677" would be rendered as > "1677-05-00" > > Has anyone done something like that in Python? > > > The datetime module has lots of capabilities including the several you mention. See https://docs.python.org/2/library/datetime.html Gary Herron