Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81182 > unrolled thread

Using Python for date calculations

Started bySteve Hayes <hayesstw@telkomsa.net>
First post2014-11-21 10:35 +0200
Last post2014-11-22 07:34 +0200
Articles 9 on this page of 29 — 13 participants

Back to article view | Back to comp.lang.python


Contents

  Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 10:35 +0200
    Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 19:40 +1100
      Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 12:15 +0200
        Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:18 +1100
        Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 10:33 +0000
          Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:47 +1100
          Re: Using Python for date calculations random832@fastmail.us - 2014-11-21 08:54 -0500
            Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 14:54 +0000
          Re: Using Python for date calculations random832@fastmail.us - 2014-11-21 08:58 -0500
            Re: Using Python for date calculations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-22 01:55 +1100
              Re: Using Python for date calculations Ned Batchelder <ned@nedbatchelder.com> - 2014-11-21 10:25 -0500
          Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-22 01:08 +1100
        Re: Using Python for date calculations Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-21 14:50 -0500
          Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:07 +0200
            Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-22 16:13 +1100
    Re: Using Python for date calculations Gary Herron <gary.herron@islandtraining.com> - 2014-11-21 00:50 -0800
    Re: Using Python for date calculations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-21 10:20 +0000
      Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 10:38 +0000
      Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 17:50 +0200
        Re: Using Python for date calculations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-21 16:01 +0000
    Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:27 +1100
    Re: Using Python for date calculations duncan smith <buzzard@invalid.invalid> - 2014-11-21 17:03 +0000
      Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 21:48 +0200
        Re: Using Python for date calculations Dennis Lee Bieber <bieber.genealogy@earthlink.net> - 2014-11-21 15:32 -0500
    Re: Using Python for date calculations Dennis Lee Bieber <bieber.genealogy@earthlink.net> - 2014-11-21 14:35 -0500
      Re: Using Python for date calculations Paul Blair <p.blair@internode.on.net> - 2014-11-22 06:51 +1100
        Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:31 +0200
      Re: Using Python for date calculations Denis Beauregard <denis.b-at-francogene.com@fr.invalid> - 2014-11-21 15:07 -0500
        Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:34 +0200

Page 2 of 2 — ← Prev page 1 [2]


#81190

FromChris Angelico <rosuav@gmail.com>
Date2014-11-21 21:27 +1100
Message-ID<mailman.16092.1416565645.18130.python-list@python.org>
In reply to#81182
On Fri, Nov 21, 2014 at 9:20 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> 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.

The OP was clearly using Python 2 (as evidenced by the paren-less
'print'), so IMO a Py2 docs link is appropriate. But I would strongly
suggest that the OP move to Py3.

ChrisA

[toc] | [prev] | [next] | [standalone]


#81227

Fromduncan smith <buzzard@invalid.invalid>
Date2014-11-21 17:03 +0000
Message-ID<546f705a$2$24260$862e30e2@ngroups.net>
In reply to#81182
On 21/11/14 08:35, 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. 
> 

[snip]

This is keeping it too simple. Someone aged 50 (i.e. over 50 but not yet
51) today - 21st Nov 2014 - might have been born in 1963 or 1964
depending on their birthday. For me your calculation would return the
correct answer (born in March), for my sister it would be wrong (born in
December).

Duncan

[toc] | [prev] | [next] | [standalone]


#81242

FromSteve Hayes <hayesstw@telkomsa.net>
Date2014-11-21 21:48 +0200
Message-ID<af5v6adks75912d6lfviqv82bah8ihb7bu@4ax.com>
In reply to#81227
On Fri, 21 Nov 2014 17:03:12 +0000, duncan smith <buzzard@invalid.invalid>
wrote:

>On 21/11/14 08:35, 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. 
>> 
>
>[snip]
>
>This is keeping it too simple. Someone aged 50 (i.e. over 50 but not yet
>51) today - 21st Nov 2014 - might have been born in 1963 or 1964
>depending on their birthday. For me your calculation would return the
>correct answer (born in March), for my sister it would be wrong (born in
>December).

So it might be a year out in the case of burials, nut in the case of many
censuses they would be more likely to have been born the year before, since
most censuses are taken i8n tyhe first part of the year. So the calculation is
a rough one, but that's all I need. If sommeone is 20 in the 1871 census, I'd
put them down as born about 1850, which probably has a 65% chance o0f being
right. 


-- 
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

[toc] | [prev] | [next] | [standalone]


#81248

FromDennis Lee Bieber <bieber.genealogy@earthlink.net>
Date2014-11-21 15:32 -0500
Message-ID<2v7v6a9l2479e8ckn59l4a8cumtih69ndi@4ax.com>
In reply to#81242
On Fri, 21 Nov 2014 21:48:24 +0200, Steve Hayes <hayesstw@telkomsa.net>
declaimed the following:


>So it might be a year out in the case of burials, nut in the case of many
>censuses they would be more likely to have been born the year before, since
>most censuses are taken i8n tyhe first part of the year. So the calculation is
>a rough one, but that's all I need. If sommeone is 20 in the 1871 census, I'd
>put them down as born about 1850, which probably has a 65% chance o0f being
>right. 

	US Census, though, tends to run early to mid-summer (especially for
those available to the public -- more recent ones have an official date of
April 1; http://en.wikipedia.org/wiki/United_States_Census#History )
--
	bieber.genealogy@earthlink.net		Dennis Lee Bieber	
	HTTP://home.earthlink.net/~bieber.genealogy/

[toc] | [prev] | [next] | [standalone]


#81240

FromDennis Lee Bieber <bieber.genealogy@earthlink.net>
Date2014-11-21 14:35 -0500
Message-ID<5l4v6a1kp9chnv9lmie3sb8b1ko69kjem3@4ax.com>
In reply to#81182
On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes <hayesstw@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@earthlink.net		Dennis Lee Bieber	
	HTTP://home.earthlink.net/~bieber.genealogy/

[toc] | [prev] | [next] | [standalone]


#81244

FromPaul Blair <p.blair@internode.on.net>
Date2014-11-22 06:51 +1100
Message-ID<m4o53h$jro$1@dont-email.me>
In reply to#81240
On 22-Nov-2014 6:35 am, Dennis Lee Bieber wrote:
> On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes <hayesstw@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@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

Paul

[toc] | [prev] | [next] | [standalone]


#81273

FromSteve Hayes <hayesstw@telkomsa.net>
Date2014-11-22 07:31 +0200
Message-ID<kl607alpe7s38fru9of7je9gu6t827v8ir@4ax.com>
In reply to#81244
On Sat, 22 Nov 2014 06:51:15 +1100, Paul Blair <p.blair@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@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@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

[toc] | [prev] | [next] | [standalone]


#81245

FromDenis Beauregard <denis.b-at-francogene.com@fr.invalid>
Date2014-11-21 15:07 -0500
Message-ID<1g6v6apugp266oiots4hu3m563cml6943b@4ax.com>
In reply to#81240
On Fri, 21 Nov 2014 14:35:14 -0500, Dennis Lee Bieber
<bieber.genealogy@earthlink.net> wrote in soc.genealogy.computing:

>On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes <hayesstw@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...)

I made a lot of automated computations from census. In Quebec, we
have censuses for 1666, 1667 and 1681, and also ages in some marriage
records, marriage contracts, burials, and some more records. In
Acadia, there are other old censuses.

Sometimes, the result is accurate, i.e. there is a known baptism
and the age is matching, but in many cases either the age is not
matching or the year of birth is changing a lot depending on the
record. So, if the computation is made to give a hint about the
birth year, then the month is irrelevant. The result will be 
"about that year" and not "that year". In the database I sell, I
write exactly that, i.e. (actual example, from Acadian censuses) :

Germain, born about 1650 (census 1671), 1652 (census 1686) (census
1693), 1650 (census 1698) or 1649 (census 1699)

Marguerite, born about 1658 (census 1671), 1660 (census 1693), 1658
(census 1698) or 1661 (census 1699)

-- 
Denis Beauregard - généalogiste émérite (FQSG)
Les Français d'Amérique du Nord - www.francogene.com/genealogie--quebec/
French in North America before 1722 - www.francogene.com/quebec--genealogy/
Sur cédérom à 1785 - On CD-ROM to 1785

[toc] | [prev] | [next] | [standalone]


#81274

FromSteve Hayes <hayesstw@telkomsa.net>
Date2014-11-22 07:34 +0200
Message-ID<c0807ad9i52lfbqq8sss72uqlnqrjrnu9o@4ax.com>
In reply to#81245
On Fri, 21 Nov 2014 15:07:39 -0500, Denis Beauregard
<denis.b-at-francogene.com@fr.invalid> wrote:

>On Fri, 21 Nov 2014 14:35:14 -0500, Dennis Lee Bieber
><bieber.genealogy@earthlink.net> wrote in soc.genealogy.computing:
>
>>On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes <hayesstw@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...)
>
>I made a lot of automated computations from census. In Quebec, we
>have censuses for 1666, 1667 and 1681, and also ages in some marriage
>records, marriage contracts, burials, and some more records. In
>Acadia, there are other old censuses.
>
>Sometimes, the result is accurate, i.e. there is a known baptism
>and the age is matching, but in many cases either the age is not
>matching or the year of birth is changing a lot depending on the
>record. So, if the computation is made to give a hint about the
>birth year, then the month is irrelevant. The result will be 
>"about that year" and not "that year". In the database I sell, I
>write exactly that, i.e. (actual example, from Acadian censuses) :
>
>Germain, born about 1650 (census 1671), 1652 (census 1686) (census
>1693), 1650 (census 1698) or 1649 (census 1699)
>
>Marguerite, born about 1658 (census 1671), 1660 (census 1693), 1658
>(census 1698) or 1661 (census 1699)

Exactly!

In this kind of thing one is lookinng for a "ballpark" figure, not a
super-accurate one. 


-- 
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

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web