Using Python for date calculations

Steve Hayes hayesstw at telkomsa.net
Sat Nov 22 06:31:33 CET 2014


On Sat, 22 Nov 2014 06:51:15 +1100, Paul Blair <p.blair at internode.on.net>
wrote:

>On 22-Nov-2014 6:35 am, Dennis Lee Bieber wrote:
>> On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes <hayesstw at telkomsa.net>
>> declaimed the following:
>>
>>
>>> 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.
>>>
>> 	And it is wrong since it doesn't take into account the month.
>>
>> 	2014 - 55 => 1959
>>
>> 	But I was born in April of 1958, so any calculation done for
>> January/February/March (and the first week of April) is going to produce
>> the incorrect year (I /was/ 55 in January of 2014...)
>>
>> --
>> 	bieber.genealogy at earthlink.net		Dennis Lee Bieber	
>> 	HTTP://home.earthlink.net/~bieber.genealogy/
>>
>
>Have a read of:
>
>http://stackoverflow.com/questions/2217488/age-from-birthdate-in-python

Except that most of those examples seem to assume that you are calculating
from the current date, rather than the date of a census or the date of a
burial. Useful for future reference, perhaps, but not for the immediate
purpose of getting a rough idea of whan a person might have been born (people
also lied about their age on censuses). 

There's a date calculator in my Legacy genealogy program, which is doubtless
more accurate, but it takes too many mouse clicks to get there, and then to
get back to where I was.

I've got another nifty little utility called RJT Datecalc, which does the more
accurate stuff, but still has too many options and is too time-consuming. 

What I'm beginning to like Python for is the ability to do quick 'n dirty
little scripts for quick 'n dirty little jobs that save time and do what I
need. 

For example, I see the age of someone in a UK census, and I want to know
roughly which years I should look for their birth in something like FreeBMD.
If it says 1847, obviously I'll look for a couple of years either side because
chances are they were born in the previous year, and the age might not have
been accurate anyway. 




-- 
Steve Hayes from Tshwane, South Africa
Web:  http://www.khanya.org.za/stevesig.htm
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk



More information about the Python-list mailing list