Re: How to find difference in years between two dates?

2006-07-29 Thread thebjorn
John Machin wrote: > I don't understand. The examples that I showed went from the last day > of a month to the last day of another month. [...] Q1: is ((date-4days)+4days) == date? Q2: is (((date-4days)+1month)+4days) == date+1month? Ok, let's use Python'ish syntax (including numbering the days f

Re: How to find difference in years between two dates?

2006-07-28 Thread John Machin
thebjorn wrote: > John Machin wrote: > > Jan 31 to Feb 27: 27d (ex) 28d (in) > > Jan 31 to Feb 28: 28d (ex) 1m 1d (in) > > Jan 31 to Mar 01: 1m 1d (ex) 1m 2d (in) > > So 1 day short of 1m 1d is not 1m 0 d??? > > Exactly. Just as a person born on 1999-3-1 isn't a year old on > 2000-2-29. Perfectly

Re: How to find difference in years between two dates?

2006-07-28 Thread thebjorn
John Machin wrote: > Jan 31 to Feb 27: 27d (ex) 28d (in) > Jan 31 to Feb 28: 28d (ex) 1m 1d (in) > Jan 31 to Mar 01: 1m 1d (ex) 1m 2d (in) > So 1 day short of 1m 1d is not 1m 0 d??? Exactly. Just as a person born on 1999-3-1 isn't a year old on 2000-2-29. Perfectly regular, consistent and reasonab

Re: How to find difference in years between two dates?

2006-07-28 Thread Bruno Desthuilliers
thebjorn wrote: > Bruno Desthuilliers wrote: >> Which conversion ? How do you get the data ? as a datetime object ? as a >> (y,m,d) tuple ? as a "y-m-d" string ? Else ? > > All input routines, whether they're from a web-form, database, command > line, or anywhere else, only produce objects from th

Re: How to find difference in years between two dates?

2006-07-27 Thread John Machin
thebjorn wrote: > John Machin wrote: > > thebjorn wrote: > [...] > > > You give a good argument that the concept of a month is fuzzy > > > > Sorry, I can't imagine where you got "fuzzy" from. Perhaps you mean > > some other word. The concept is capable of being expressed precisely. > > and the se

Re: How to find difference in years between two dates?

2006-07-27 Thread thebjorn
Bruno Desthuilliers wrote: > Which conversion ? How do you get the data ? as a datetime object ? as a > (y,m,d) tuple ? as a "y-m-d" string ? Else ? All input routines, whether they're from a web-form, database, command line, or anywhere else, only produce objects from the datetime module for cale

Re: How to find difference in years between two dates?

2006-07-27 Thread thebjorn
John Machin wrote: > thebjorn wrote: [...] > > You give a good argument that the concept of a month is fuzzy > > Sorry, I can't imagine where you got "fuzzy" from. Perhaps you mean > some other word. The concept is capable of being expressed precisely. and the second to last date in January plus

Re: How to find difference in years between two dates?

2006-07-27 Thread John Machin
thebjorn wrote: > John Machin wrote: > > thebjorn wrote: > > > John Machin wrote: > > > > thebjorn wrote: > [...] > > > > Holy code bloat, Batman! Try this: > > > > > > > > return now.year - born.year - (birthday > now) > > > > > > yuck :-) > > > > But this: > > return now.year - born.year

Re: How to find difference in years between two dates?

2006-07-27 Thread thebjorn
John Machin wrote: > thebjorn wrote: > > John Machin wrote: > > > thebjorn wrote: [...] > > > Holy code bloat, Batman! Try this: > > > > > > return now.year - born.year - (birthday > now) > > > > yuck :-) > > But this: > return now.year - born.year - (birthday > now and 1 or 0) is not yuck?

Re: How to find difference in years between two dates?

2006-07-27 Thread Bruno Desthuilliers
thebjorn wrote: > Bruno Desthuilliers wrote: > [...] > >>Possible solution: >> >>import mx.DateTime as dt >>def age(date): >>return dt.Age(dt.today(), date).years >>born = dt.Date(1967, 5, 1) >>assert age(born) == 39 > > > dealbreaker: > age(datetime.date(1970,5,2)) > (snip traceback) W

Re: How to find difference in years between two dates?

2006-07-26 Thread John Machin
thebjorn wrote: > John Machin wrote: > > thebjorn wrote: > [...] > > > > > > def age(born): > > > now = date.today() > > > birthday = date(now.year, born.month, born.day) > > > > Bad luck if the punter was born on 29 Feb and the current year is not a > > leap year. > > Good catch! Tha

Re: How to find difference in years between two dates?

2006-07-26 Thread Gerhard Fiedler
On 2006-07-26 17:50:43, thebjorn wrote: > I don't agree that the irregular sized months cause a problem in this > case. They do cause a problem if you're asking "when is today + one > month?", i.e. there isn't an unambiguous answer to that question in > general (e.g. if today was January 31). We'r

Re: How to find difference in years between two dates?

2006-07-26 Thread thebjorn
Bruno Desthuilliers wrote: [...] > Possible solution: > > import mx.DateTime as dt > def age(date): > return dt.Age(dt.today(), date).years > born = dt.Date(1967, 5, 1) > assert age(born) == 39 dealbreaker: >>> age(datetime.date(1970,5,2)) Traceback (most recent call last): File "", line 1,

Re: How to find difference in years between two dates?

2006-07-26 Thread thebjorn
John Machin wrote: > thebjorn wrote: [...] > > > > def age(born): > > now = date.today() > > birthday = date(now.year, born.month, born.day) > > Bad luck if the punter was born on 29 Feb and the current year is not a > leap year. Good catch! Thanks! [..] > Holy code bloat, Batman! T

Re: How to find difference in years between two dates?

2006-07-26 Thread thebjorn
Roy Smith wrote: > "thebjorn" <[EMAIL PROTECTED]> wrote: > > > def age(born): > > now = date.today() > > birthday = date(now.year, born.month, born.day) > > return now.year - born.year - (birthday > now and 1 or 0) > > I don't get that last line. There's two things in particula

Re: How to find difference in years between two dates?

2006-07-26 Thread Bruno Desthuilliers
John Machin wrote: > Bruno Desthuilliers wrote: > >>John Machin wrote: >> >>>Bruno Desthuilliers wrote: >> >>>Which pieces of the following seem to be working to you? >> >>John, it seems you failed to notice the use of "may" and "seems" in my >>post. IIRC, both are supposed to strongly suggest a l

Re: How to find difference in years between two dates?

2006-07-26 Thread bearophileHUGS
Roy Smith: > 2) I find the "and 1 or 0" part very confusing. I can't remember all the > minor rules about operator precedence, but I'm sure this works out to some > clever hack involving boolean short-circuit evaluation to get around the > lack of a ternary operator in python. If I need to pull o

Re: How to find difference in years between two dates?

2006-07-26 Thread John Machin
Bruno Desthuilliers wrote: > John Machin wrote: > > Bruno Desthuilliers wrote: > > > > > Which pieces of the following seem to be working to you? > > John, it seems you failed to notice the use of "may" and "seems" in my > post. IIRC, both are supposed to strongly suggest a lack of certitude. > >

Re: How to find difference in years between two dates?

2006-07-26 Thread Bruno Desthuilliers
John Machin wrote: > Bruno Desthuilliers wrote: > >>thebjorn wrote: >> >>>For the purpose of finding someone's age I was looking for a way to >>>find how the difference in years between two dates, so I could do >>>something like: >>> >>> age = (date.today() - born).year >>> >>>but that didn't wor

Re: How to find difference in years between two dates?

2006-07-26 Thread John Machin
Bruno Desthuilliers wrote: > thebjorn wrote: > > For the purpose of finding someone's age I was looking for a way to > > find how the difference in years between two dates, so I could do > > something like: > > > > age = (date.today() - born).year > > > > but that didn't work (the timedelta class

Re: How to find difference in years between two dates?

2006-07-26 Thread Roy Smith
"thebjorn" <[EMAIL PROTECTED]> wrote: > def age(born): > now = date.today() > birthday = date(now.year, born.month, born.day) > return now.year - born.year - (birthday > now and 1 or 0) I don't get that last line. There's two things in particular that are puzzling me. 1) Wh

Re: How to find difference in years between two dates?

2006-07-26 Thread Bruno Desthuilliers
thebjorn wrote: > For the purpose of finding someone's age I was looking for a way to > find how the difference in years between two dates, so I could do > something like: > > age = (date.today() - born).year > > but that didn't work (the timedelta class doesn't have a year > accessor). > > I

Re: How to find difference in years between two dates?

2006-07-26 Thread John Machin
thebjorn wrote: > For the purpose of finding someone's age I was looking for a way to > find how the difference in years between two dates, so I could do > something like: > > age = (date.today() - born).year > > but that didn't work (the timedelta class doesn't have a year > accessor). > > I loo

How to find difference in years between two dates?

2006-07-26 Thread thebjorn
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that didn't work (the timedelta class doesn't have a year accessor). I looked in the docs and the cookbook,