Using Python for date calculations
alister.nospam.ware at ntlworld.com
Fri Nov 21 11:38:48 CET 2014
On Fri, 21 Nov 2014 10:20:06 +0000, Mark Lawrence wrote:
> On 21/11/2014 08:50, Gary Herron wrote:
>> 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
>>> 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
>> See https://docs.python.org/2/library/datetime.html
>> Gary Herron
> As we're now firmly heading into the Python 3 era would people please be
> kind enough to use the Python 3 links. I know it's only a single
> character change but it's the principle to me. TIA.
I think this was because the OP is clearly using python 2
he may be better of moving to python 3 but providing links to documents
of his current version is probably more helpful than providing python 3
links-in this case
Martin was probably ripping them off. That's some family, isn't it?
Incest, prostitution, fanaticism, software.
-- Charles Willeford, "Miami Blues"
More information about the Python-list